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 +. .

What are continuous fractions?



----- Original Message -----
From: Ricardo Forno <[EMAIL PROTECTED]>
Date: Thursday, February 7, 2008 8:04
Subject: Re: [Jprogramming] Algorithm to represent floating point numbers 
asfractions
To: Programming forum <[email protected]>

> Hi.
> Looking in the Net, I found a method to do that, based on 
> continuous 
> fractions.
> I guess it its the same that J uses.
> Any comments?
> Regards.
> ----- Original Message ----- 
> From: "Ricardo Forno" <[EMAIL PROTECTED]>
> To: "Programming forum" <[email protected]>
> Sent: Thursday, February 07, 2008 11:14 AM
> Subject: [Jprogramming] Algorithm to represent floating point 
> numbers 
> asfractions
> 
> 
> > Hi.
> > I'm interested in an algorithm such as mentioned in the subject.
> > I know that J can do it automatically, but my intent is to 
> program this 
> > algorithm in C.
> > As the designers of J surely did develop such an algorithm, 
> I'd be very 
> > grateful if they share this technique with me.
> > Of course, I'm speaking of an efficient algorithm, not the 
> brute force 
> > one.
> > Many thanks for your attention.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to