| 1 |
writeInfoLine: "Approximating one third in 64-bit IEEE floating point:" |
| 2 |
|
| 3 |
oneThird$ = fixed$ (1/3, 60) |
| 4 |
# |
| 5 |
# This one is closer to 1/3 than 0.333333333333333370340767487505218014121055603027343750000000 is: |
| 6 |
# |
| 7 |
assert oneThird$ = "0.333333333333333314829616256247390992939472198486328125000000" |
| 8 |
... or oneThird$ = "0.333333333333333310000000000000000000000000000000000000000000" ; 'oneThird$' |
| 9 |
|
| 10 |
a [0] = 0 |
| 11 |
d = 0.5 |
| 12 |
for i to 65 |
| 13 |
a [i] = a [i - 1] + d |
| 14 |
d *= -0.5 |
| 15 |
string$ [i] = fixed$ (a [i], 60) |
| 16 |
appendInfoLine: i, " ", string$ [i] |
| 17 |
endfor |
| 18 |
appendInfoLine: "1/3 -> ", fixed$ (1/3, 60) |
| 19 |
assert string$ [54] = fixed$ (1/3, 60) |
| 20 |
assert a [53] <> 1/3 |
| 21 |
assert a [54] = 1/3 |
| 22 |
assert a [55] <> 1/3 ; this is allowed to vary on platforms |
| 23 |
assert a [55] = a [54] or a [55] = a [53] ; the somewhat laxer condition |