Using facilities from
http://www.jsoftware.com/jwiki/Essays/Extended_Precision_Functions
t=: 1+_1 0* 2e_16
hex t NB. 0
3feffffffffffffe
3ff0000000000000
0j20 ": ,. t NB. 1
0.99999999999999978000
1.00000000000000000000
e=: 2^27x NB. 2
0j20 ": (e-%e)%(e+%e) NB. 3
0.99999999999999988898
e1=: exp x:!.0 ] 0.2 + 27*^.2 NB. 4
0j20 ": (e1-%e1)%(e1+%e1) NB. 5
0.99999999999999992558
Note 0: this shows that t are consecutive
IEEE numbers. 0{t is the next number
smaller than 1, 1{t is exactly 1.
Note 1: their decimal representations.
Note 2: Exactly ^T where T=: 27*^.2
Note 3: The exact value of tanh T displayed
to 20 decimal places.
Note 4: converting 0.2+T into a rational r ,
and then calculating tanh r exactly.
Note 5: tanh r displayed to 20 decimal places.
Therefore, tanh T calculated exactly should
be represented by 3feffffffffffffe (1-2e_16),
and tanh 0.2+T should be by 3ff0000000000000 (1).
----- Original Message -----
From: Zsbán Ambrus <[EMAIL PROTECTED]>
Date: Sunday, March 2, 2008 9:03
Subject: Re: [Jprogramming] What is interesting about 27*^.2 ?
To: Programming forum <[email protected]>
> On Sun, Mar 2, 2008 at 7:45 AM, Roger Hui <[EMAIL PROTECTED]> wrote:
> > T=: 27*^.2
> >
> > (spoiler alert.)
> >
> >
> > What is interesting about T=:27*^.2 ? In IEEE 64-bit
> > floating point calculation, for all y>:T, 1=tanh y
> > (and _1=tanh -y) and T is the smallest number with
> > this property.
> >
> > tanh=: (^ - [EMAIL PROTECTED]) % (^ + [EMAIL PROTECTED])
>
> I would rather defined tanh as
>
> tanh1 =: 7&o.
>
> If you use this definition, then the above statement is not
> true. In
> fact, (tanh1 0.2 + T) is still not exactly one. This is
> similary to
> what I get if I use the tanh function in the GNU libc, which is
> supposed to be very precise, so I assume that for such large values,
> tanh1 gives a more precise result than your tanh function (the
> difference is minute of course).
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm