|
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:
|
[Prev in Thread] | Current Thread | [Next in Thread] |