First, let's look at some experimental results in Dyalog 12.1:
Code: Select all
⎕pp←17
⎕ml←0
⎕ct←0
⊃10*-⍳10
0.1
⊃10*-⍳11
0.09999999999999998
⊃10*-⍳51
0.10000000000000006
⊃10*-⍳1151
0.09999999999999992
If I got Goeff's post right, the interpreter should in any case first calculate the value of "10 to the power of the first element of the vector" of negative integers, which in any of the cases would be 10 to the power of -1. If afterwards the interpreter chooses to use this value as a base to multiply with or divide by some other value, this multiplication or division operation should not harm the base value calculated in the first place. But as we can see in the example above, the value is harmed.
There seem to be several algorithms involved in calculating the series of powers, depending of the length or value of the progression vector used as the right argument of the * function.
Geoff pointed out that decimal floating point numbers would cure such cases. I tend to agree for cases where the left argument of the * function is a product of 2s and 5s. I tend to doubt for all other integers.
Code: Select all
⊃9*-⍳7
0.1111111111111111
⊃9*-⍳11
0.11111111111111109
⊃9*-⍳51
0.11111111111111105
⊃9*-⍳1151
0.11111111111111097
Even with decimal floating point numbers implemented we may still need a little bit of tolerance in comparisons, with ⎕CT set to a value different to zero.
Uwe