[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: |
Mon, 28 Aug 2017 19:59:19 -0500 |
Louis,
Thanks for the quick response.
After working with the technique a bit, I observe that as long
as the rational number denominator is well within the range of integers
representable by floating numbers, 1 ∧ n returns the correct result.
But if the absolute value of the denominator exceeds 2 ⋆ 35, the
technique returns incorrect results. For instance,
fiMax ← × / 53 ⍴ 2 ⍝ largest integer 53-bit f.p. mantissa holds
fiMax
╔════════════════╗
║9007199254740992║
╚════════════════╝
1 ∧ fiMax ⍝ Correct result for fiMax
╔════════════════╗
║9007199254740992║
╚════════════════╝
1 ∧ ÷ fiMax ⍝ Incorrect result. 1 is numerator of reciprocal.
╔═╗
║0║
╚═╝
I was hoping to be able to access correct rational number parts
even when they approach the ⎕SYL[20;2] limit of 9200000000000000000.
It seems a shame to loose so much of the integer range because floating
point operations are sneaking into the numerator and denominator access
methods.
Regards,
Fred
On Tue, 2017-08-29 at 00:08 +0200, Louis de Forcrand wrote:
> Hi,
>
> No APL kb with me right now, sorry :(
>
> 1 LCM n
>
> gives the numerator of a fraction (floating or exact). If you need
> the denominator, do the same with the inverse of n. If you need both,
> for example:
>
> 1 LCM n POW 1 _1
>
> Cheers,
> Louis
>
> > On 28 Aug 2017, at 23:24, Frederick Pitts <address@hidden>
> > wrote:
> >
> > Hello,
> >
> > Is there an existing mechanism for accessing rational number
> > numerator and denominator parts analogous to that for accessing
> > complex
> > number real and imaginary parts? If yes, please let me know
> > how. If
> > no, can a mechanism be implemented?
> >
> > Respectfully,
> >
> > Fred
> >
>
>
Re: [Bug-apl] Access to rational number numerator and denominator, Juergen Sauermann, 2017/08/29