bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Access to rational number numerator and denominator


From: Juergen Sauermann
Subject: Re: [Bug-apl] Access to rational number numerator and denominator
Date: Wed, 30 Aug 2017 13:43:20 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

Hi Fred,

Rational. and non-rational numbers use the same Cell type (FloatCell).

Non-Rational numbers have a denominator = 0 and store their value in value.fval.u1.flt (which is a double in union u1)
Rational numbers have a denominator >= 1 and store their value in value.fval.u1.num (which is an int64_t in union u1)

So basically a rational number uses the same space that a complex number would use for its imaginary part (to avoid an
increase of the Cell size by introducing rational numbers).

26 ⎕CR has nothing to do with all of this.
27 ⎕CR returns the primary value of a Cell (which is always an integer that was possibly cast from a different type like
APL_Char or APL_Float to APL_Integer = int64_t).
28 ⎕CR is 0 or the secondary value of a Cell (imaginary part for Complex Cells, Denominator for Rational FloatCells, ...),
and is also always an APL_Integer.

      28 ⎕CR ÷ 2
2


So the denominator is NOT represented by a double but by an int64_t.

The idea behind 27/28 ⎕CR is to get the underlying machine representation of the value(s) store in a Cell (similar to dyadic ⎕CR
in good old APL68000) which by chance is the denominator of a rational float value.

Hope that explains it,

/// Jürgen


On 08/30/2017 07:59 AM, Frederick Pitts wrote:
Hello Jürgen,

After reading your email and the apl.html documentation on ⎕CR and so, I've have two questions:

1) How does one know B is a rational number? The apl.html documentation for 26 ⎕CR B does not show
that there is a cell type for rationals and I could not locate one in the source code. Admittedly my examination was cursory.
2) Why is a real number being used to represent the numerator of a rational number? I thought ~63-bit
integers would consistently be used to represent the parts of a rational. 26 ⎕CR ÷ 2 yields 32 indicating that 1 is being represented by a real rather than an integer. That is puzzling to me. It almost seems irrational, no pun intended.

Regards.


On Tue, 2017-08-29 at 12:51 +0200, Juergen Sauermann wrote:
Hi Fred,

the existing mechanism is 27 ⎕CR B to get the numerator of B and 28 ⎕CR to get the denominator > 0
of a quotient or 0 if the number is not a quotient (and then 27 ⎕CR is the double B cast to
uint64_t.

Unfortunately there was a bug 28 ⎕CR returning always 0. Fixed in SVN 1004.

Best Regards,
/// Jürgen


On 08/28/2017 11:24 PM, Frederick Pitts 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]