[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-apl] Access to rational number numerator and denominator
From: |
Frederick Pitts |
Subject: |
Re: [Bug-apl] Access to rational number numerator and denominator |
Date: |
Tue, 29 Aug 2017 05:00:41 -0500 |
Guys,
To make it clear, I'm not asking for bigints. I'm just seeking to get the maximum benefit of having rational numbers with, as Xtian says, ~63-bit numerator and denominators. As long as you limit yourself to using addition, subtraction, multiplication, and division and avoid overrunning the ~63-bit limitation, the rationals work as expected up to that ~63-bit limit AFAIK. But use any other function, say power (⋆) or least common multiple (∧), difficult to predict floating-point conversions reduce the ~63-bits to 53-bits or less and produce incorrect results.
Louis recommended the LCM function as a means of separating a rational into its numerator and denominator so I could program with them individually. Louis mentioned that he did not have access to a APL keyboard while composing his email, so I took his use of LCM to mean the native
Gnu-APL ∧ function and that is why I tried using it. Turns out that Ken Iverson presented APL code for GCD and LCM functions in his "Notation as a Tool for Thought" Turing Award paper that avoid floating point arithmetic. Preliminary testing indicates those implementations will do the job.
Still, if Gnu-APL is going to support rational numbers, an efficient mechanism for accessing numerators and denominators similar to the circle function (○) with 9 and 11 left arguments for accessing the real and imaginary parts of complex numbers is needed. Could implementing this functionality be added to someone's to-do list, please?
Regards,
Fred
On Tue, 2017-08-29 at 10:57 +0800, Elias Mårtenson wrote:
A bigint is an arbitrary-precision integer. Such as what is provided in Lisp:
In Lisp, I get the correct rational number:
CL> (/ (expt 2 1000) 3)
10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376/3
In GNU APL:
⎕PS←1 0
3÷⍨2⋆1000
3.571695357E300
With bigints, the APL result would be similar to that of Lisp.
Regards,
Elias
Re: [Bug-apl] Access to rational number numerator and denominator, Juergen Sauermann, 2017/08/29