David Ward Lambert wrote:
> I'm somewhat surprised that antibase gives up at 14 decimal digits of
> precision.
To elaborate a bit, this isn't a bug, it's a feature; a consequence of
comparison tolerance.
When you see the magic number "14 decimal digits of precision" you should get
suspicious, because that value is (approximately) J's
default comparison tolerance:
9!:18'' NB. Query global cmp tolerance (default)
5.68434e_14
Note the actual value is not exactly 10^_14 (it's 2^_44, see [1]), but when
looking at numbers formatted as decimals the difference
starts showing up at the 14th digit after the decimal point.
So that's why #:!.0 gave the values you expected when #: didn't; the latter
considers two values equal if they're within 2^_44 of
each other, and so #: will "give up" (actually, consider its work complete, so
maybe "clock out"?) then, whereas the former turns
off tolerance and only considers two values equal if they're identical to the
last bit.
Of course turning off tolerance only works if your values are actually
non-tolerantly equal, which is rare (hence the need for
tolerance in the first place). Of course special values like pi get special
treatment, and libc will make sure they're specified
correctly down to the last bit (which is why the last row of the output I
presented was correct to the last integer).
Just don't depend on that for your own calculated values (even those derived
from special values like pi); if you really need more
precision, then you can use x: (and friends), as Raul advised.
David Ward Lambert wrote:
> Consider #:!. .
I responded:
> Have you tried that?
I should've been more explicit that this construct is undocumented, and can
only be discovered through trial. The link I gave
http://www.jsoftware.com/jwiki/System/Interpreter/Requests#documentfitmorecompletely
provides reasons why one might suspect that #:!. would work, and why one might
try it, even though it's not documented (via a link
to a Forum post describing the implementation of !.).
The link also gives a more complete list of possible fits, documented or not,
and incidentally serves as an example of introspective
J code (using code to investigate the interpreter & its secrets).
-Dan
[1] Dictionary page for = (which describes tolerance):
If x or y is a finite floating-point or complex
number, the comparison is made with a tolerance
t , normally 2 to the power _44
http://www.jsoftware.com/help/dictionary/d000.htm
See also
Foreigns 9!:18 and 19 for setting global tolerance:
http://www.jsoftware.com/help/dictionary/dx009.htm#18
Fit !. for setting local tolerance:
http://www.jsoftware.com/help/dictionary/d411.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm