----- Original Message -----
From: "Roger Hui" <[EMAIL PROTECTED]>
To: "Programming forum" <[email protected]>
Sent: Thursday, February 07, 2008 3:11 PM
Subject: Re: [Jprogramming] Algorithm to represent floating point
numbersasfractions
pq=: 3 : 0
q=. <. 0.5 + % 1 +. y
p=. <. 0.5 + y * q
p,q
)
pq 0.625
5 8
pq 0.07
7 100
] y=: ? 0
0.536676
pq y
9.08637e12 1.69308e13
%/ pq y
0.536676
y - %/ pq y
_4.51861e_14
Note that +. (GCD) is tolerant. Depending on your needs you
may want to use +.!.0 (0 tolerance) instead of +. .
I found the detailed algorithm here (Spanish explanation). Anyway, it is not
difficult at all, and it adapts better to C programming:
http://enciclopedia.us.es/index.php/Fracci%C3%B3n_continua
Thanks a lot.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm