Typos:  all comparisons below should be with 0 tolerance,
viz., =!.0 and >:!.0 .



----- Original Message -----
From: Roger Hui <[EMAIL PROTECTED]>
Date: Saturday, March 1, 2008 22:45
Subject: [Jprogramming] What is interesting about 27*^.2 ?
To: Programming forum <[email protected]>

> What is interesting about 27*^.2 ?
> 
>    T=: 27*^.2
>    T
> 18.715
>    ":!.18 T
> 18.714973875118524
> 
> (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])
> 
>    tanh T
> 1
>    1 - tanh T
> 0
> 
>    hex  =: ([EMAIL PROTECTED]) }. 2&(3!:3)
>    unhex=: (3!:2) @ ((}: 2 (3!:3) 0.5)&,) " 1
> 
>    hex 1,tanh T
> 3ff0000000000000
> 3ff0000000000000
> 
>    hex T
> 4032b708872320e2
>    t=. unhex (}:,hex T),'1'  NB. the next smaller 
> number   hex t
> 4032b708872320e1
>    tanh t
> 1
>    1 - tanh t
> 2.22045e_16
>    hex tanh t
> 3feffffffffffffe
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to