APL takes care of binary-vs-decimal inexactness too, so 3×(1÷3) is really 1:
3×(1÷3)
How is this done? How well it scale? I suppose well, because APL is good for math, rigth? But then I remember that must be slow...? APL takes care of binary-vs-decimal inexactness too, so 3×(1÷3) is really 1:
3×(1÷3)
How is this done? How well it scale? I suppose well, because APL is good for math, rigth? But then I remember that must be slow...?However, Dyalog just uses IEEE doubles (with an error in place of infinities or NaNs; also you can configure to use higher-precision decimal floats), no different from JavaScript. The result of, say, 0.1+0.2, is not the same as 0.3, it's just equal under tolerant comparison.
[0] https://www.dyalog.com/blog/2018/11/tolerated-comparison-par...
The "fun" is with, e.g. `0.1 + 0.2`. I just tried on the website
0.1 + 0.2 - 0.3
2.775557562E¯17
which agrees: julia> 0.1 + (0.2 - 0.3)
2.7755575615628914e-17 say 3×(1÷3)
# 1
It works because `1÷3` is a rational number. my \rat = 1÷3;
say rat.numerator; # 1
say rat.denominator; # 3
If you multiply it by 3, you get another rational number which represents 1. my \result = 3×rat;
say result; # 1
say result.numerator; # 1
say result.denominator; # 1
---Now that this may be slower than using floating point numbers, but it isn't that much slower. You only have two integers that you have to manage.
Actually on many older processors there wasn't built in support for floating point numbers, so it might actually have been faster to use rationals like this.
(I'm not sure if this is how APL handled it.)
---
APL happens to be one of the languages Raku copied ideas from
×/⍳10
Translated to Raku [×] 1..10
That is rather than `×/…` it is written `[×] …`. Partly because `/` is the ASCII version of the division operator.We could go further towards replicating it.
{
sub prefix:<⍳> (UInt \n){ 1..n }
sub infix:</> (&f, +list){
[[&f]] list
}
constant term:<×> = &infix:<×>;
say ×/⍳10;
# 3628800
}The only things I remember are that a symbol could could do 3 things when used with a monad, dyad, or infix, and that it was very hard to read anyone else's code because it was so terse.
They also went through a phase of naming their Java classes things like com.a.b after getting used to K's terseness. Fortunately, that didn't last very long.
3 1 3 */ .s <1> 1 ok