Generalised floating point multiplication: Difference between revisions

m
(Added Wren)
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by 2 users not shown)
Line 58:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.3.3 algol68g-2.3.3].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
'''File: Template.Big_float.Multiplication.a68'''<langsyntaxhighlight lang="algol68">##########################################
# TASK CODE #
# Actual generic mulitplication operator #
Line 116:
 
OP *:= = (REF DIGITS lhs, DIGIT arg)DIGITS: lhs := lhs * INITDIGITS arg;
</langsyntaxhighlight>'''File: Template.Balanced_ternary_float.Base.a68'''<langsyntaxhighlight lang="algol68">PR READ "Template.Big_float_BCD.Base.a68" PR # [[rc:Generalised floating point addition]] #
 
################################################################
Line 151:
OD;
out SHR (UPB s-point)
);</langsyntaxhighlight>'''File: test.Balanced_ternary_float.Multiplication.a68'''<langsyntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #
####################################################################
# A program to test arbitrary length floating point multiplication #
Line 200:
printf($l$)
OD
)</langsyntaxhighlight>'''Output:'''
<pre>
a = +523.23914037494284407864655 +-0++0+.+-0++0+
Line 241:
{{trans|Phix}}
In the interests of brevity many of the comments and all of the commented-out code has been omitted.
<langsyntaxhighlight lang="go">package main
 
import (
Line 796:
test("septemvigesimal", septemVigesimal)
multTable()
}</langsyntaxhighlight>
 
{{out}}
Line 883:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Formatting
import Base.BigInt, Base.BigFloat, Base.print, Base.+, Base.-, Base.*
 
Line 1,051:
 
code_reuse_task(BalancedTernary)
</langsyntaxhighlight>{{out}}
<pre>
a = +-0++0+.+-0++0+ = 523.23914
Line 1,099:
0.1 accurate to several million decimal places, but just never quite exact.
 
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Generic_multiplication.exw</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">MAX_DP</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">81</span>
Line 1,562:
<span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"hexadecimal"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">hexadecimal</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"septemvigesimal"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">septemvigesimal</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
The printed decimal output is inherently limited to IEEE 754 precision, hence I deliberately limited output (%.16g)
because it is silly to try and go any higher, whereas the output from b_mul() is actually perfectly accurate,
Line 1,620:
=== multiplication table ===
Without e notation, with hexadecimal across, septemvigesimal down, and balanced ternary contents!
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"* |"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">12</span> <span style="color: #008080;">do</span>
Line 1,639:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,674:
=={{header|Wren}}==
{{trans|Phix}}
{{libheader|Wren-str}}
Via the Go entry.
{{libheader|Wren-iterate}}
<lang ecmascript>import "/str" for Str
{{libheader|Wren-fmt}}
import "/trait" for Stepped
ViaTranslated via the Go entry.
import "/fmt" for Fmt
<langsyntaxhighlight ecmascriptlang="wren">import "./str" for Str
import "./traititerate" for Stepped
import "./fmt" for Fmt
 
var maxdp = 81
Line 2,157 ⟶ 2,160:
test.call("hexadecimal", hexadecimal)
test.call("septemvigesimal", septemVigesimal)
multTable.call()</langsyntaxhighlight>
 
{{out}}
9,485

edits