immutable class RAT < $IS_LT{RAT}, $STR |
---|
**** | Rational numbers. A rational number is represented by by two integers u and v (numerator and denominator) and always normalized, i.e. u.gcd(v) = 1 and v > 0. |
$STR | $IS_LT{_} | $IS_EQ |
attr u, v: INTI; |
---|
**** | numerator, denominator |
attr u, v: INTI; |
---|
**** | numerator, denominator |
abs: SAME |
---|
ceiling: INTI |
---|
create (u: INT): SAME |
---|
create (u, v: INT): SAME |
---|
create (u: INTI): SAME |
---|
create (u, v: INTI): SAME |
---|
cube: SAME |
---|
div (y: SAME): SAME |
---|
float (n, b: INT): TUP{BOOL, INTI, INT, BOOL} |
---|
**** | Returns the floating point number x = s * m * b^e that is closest to self. x is returned in form of a 4-tupel (s, m, e, a). n specifies the length of the mantissa m in no. of digits to the base b. The mantissa is either 0 (self = 0) or normalized, i.e. it holds: b^(n-1) <= mantissa < b^n. The sign s indicates a negative number. The flag a indicates that x is accurate (i.e. x = self). Rounding to the nearest is used; ties are broken by rounding to even (IEEE rounding).
The implementation is essentialy AlgorithmM described by W.D. Clinger in "How to Read Floating Point Numbers Accurately", PLDI 1990 proceedings, p. 92-101. |
floor: INTI |
---|
hash:INT |
---|
is_eq (y: SAME): BOOL |
---|
is_int: BOOL |
---|
is_lt (y: SAME): BOOL |
---|
is_neg: BOOL |
---|
is_pos: BOOL |
---|
is_zero: BOOL |
---|
minus (y: SAME): SAME |
---|
mod (y: SAME): SAME |
---|
negate: SAME |
---|
plus (y: SAME): SAME |
---|
pow (i: INT): SAME |
---|
**** | Returns self raised to the power i. Returns 1 for i < 0.
|
sign: INT |
---|
square: SAME |
---|
str (n: INT): STR |
---|
**** | Returns a string representation of self in decimal floating point form [sign] digit '.' {digit} ['e' [sign] digit {digit}] where n specifies the number of digits of the mantissa.
|
str: STR |
---|
**** | Returns a string representation of self in the form u/v or u (if self.is_int).
|
times (y: SAME): SAME |
---|
attr u, v: INTI; |
---|
**** | numerator, denominator |
attr u, v: INTI; |
---|
**** | numerator, denominator |