number.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand        --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------


abstract class $ORDINAL{NTP} < $NFE{NTP}, $CONVERSION{NTP},

abstract class $ORDINAL{NTP} < $NFE{NTP}, $CONVERSION{NTP}, $COUNTS{NTP}, $LIMITED{NTP} is -- This abstract class models the arithmetic domain of cardinal numbers. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 20 Dec 00 kh Original when revising numeric inheritance succ : NTP ; -- This feature returns the ordinal number which is next in sequence -- after self. succ( count : NTP ) : NTP ; -- This feature returns the ordinal number which is offset towards a -- higher number by count from self! pred : NTP ; -- This feature returns the ordinal number which precedes self in -- sequence. pred( count : NTP ) : NTP ; -- This feature returns the ordinal number which is offset towards a -- lower number by count from self! end ; -- $ORDINAL{NTP}

abstract class $SIMPLE_NUM{NTP < $NFE{NTP}} < $CONVERSION{NTP},

abstract class $SIMPLE_NUM{NTP < $NFE{NTP}} < $CONVERSION{NTP}, $ARITHMETIC{NTP}, $COUNTS{NTP}, $SEQUENCERS{NTP}, $HASH is -- This class is an abstraction over number classes for which the -- concept of linear range and tolerance limits are meaningful. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 6 Dec 00 kh Original when simplifying numerics two : NTP ; -- This feature returns the numeric value 'two' as a number of the -- inheriting class. max( other : NTP ) : NTP ; -- This routine returns the value which is the larger of self and other. min( other : NTP ) : NTP ; -- This feature returns the value which is the lesser of self and other. in_range( lower : NTP, upper : NTP ) : BOOL ; -- This predicate returns true if and only if self has a value between -- lower and upper inclusive. in_range( rng : $RANGE{NTP} ) : BOOL ; -- This predicate returns true if and only if self has a value within -- the given range. in_tolerance( tolerance, val : NTP ) : BOOL ; -- This predicate returns true if and only if the value of self is -- within the given tolerance of val. end ; -- $SIMPLE_NUM{NTP}

abstract class $WHOLE_NUM{NTP} < $NFE{NTP}, $SIMPLE_NUM{NTP}

abstract class $WHOLE_NUM{NTP} < $NFE{NTP}, $SIMPLE_NUM{NTP} is -- This class is an abstraction over number classes the values of which -- have an exact representation in a computer system, including infinite -- number representations. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 20 Dec 00 kh Original when simplifying numerics is_even : BOOL ; -- This feature returns true if and only if self is an even valued -- number (ie self mod 2 is zero). is_odd : BOOL ; -- This predicate returns true if and only if self is an odd valued -- number. is_prime : BOOL ; -- This feature returns true if and only if self is a prime number. is_prime_to( other : NTP ) : BOOL ; -- This feature returns true if and only if self is relatively prime -- to other. evenly_divides( other : NTP ) : BOOL ; -- This predicate returns true if and only if self is an exact divisor -- of other. ceiling( val : NTP ) : NTP ; -- This routine returns the smallest whole number value greater than -- or equal to self which is also a multiple of val. gcd( other : NTP ) : NTP ; -- This feature returns the greatest common divisor of self and other. -- The result is always positive such that `other.gcd(0) = other.abs'. extended_gcd( other : NTP, out self_factor, out i_factor : NTP ) : SAME ; -- This routine returns the result of applying the extended Euclidean -- algorithm (Geddes et al, p36) to self and other. lcm( other : NTP ) : NTP ; -- This feature returns the least common multiple of self and other. factorial : NTP ; -- This feature returns the factorial of self, providing that this is -- representable, otherwise nil. end ; -- $WHOLE_NUM{NTP}

abstract class $CARDINAL{NTP < $ARITHMETIC{NTP}} < $WHOLE_NUM{NTP},

abstract class $CARDINAL{NTP < $ARITHMETIC{NTP}} < $WHOLE_NUM{NTP}, $LIMITED{NTP}, $VALUE_ITERS{NTP} is -- This abstract class models the arithmetic domain of cardinal numbers. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 20 Dec 00 kh Original when revising numeric inheritance pow( exp : NTP ) : NTP ; -- This feature returns self to the power exp, providing that the result -- is representable, otherwise it shall return nil! exp2 : NTP ; -- This feature returns the number which is 2 to the power of self, -- providing that this is representable, otherwise nil is to be returned. exp10 : NTP ; -- This routine returns 10 to the power of self provided that this is -- representable in the value domain, otherwise nil. log2 : NTP ; -- This feature returns the value of log(self) to the base 2, rounded if -- necessary for whole number classes. end ; -- $CARDINAL{NTP}

abstract class $INTEGER{NTP} < $CARDINAL{NTP}, $SIGNED{NTP}

abstract class $INTEGER{NTP} < $CARDINAL{NTP}, $SIGNED{NTP} is -- This class is an abstraction over number classes the values of which -- arein the mathematical domain of integers. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 18 Dec 00 kh Original when simplifying numerics end ; -- $INTEGER{NTP}

abstract class $RATIONAL{NTP} < $CONVERSION{NTP},

abstract class $RATIONAL{NTP} < $CONVERSION{NTP}, $ARITHMETIC{NTP}, $SIGNED{NTP}, $VALUE_ITERS{NTP}, $LOG_OPS{NTP}, $ROUNDING{NTP}, $HASH is -- This abstraction models the mathematical domain of rational numbers. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 6 Dec 00 kh Original for revised inheritance graph end ; -- $RATIONAL{NTP}

abstract class $REAL{NTP} < $RATIONAL{NTP}, $LIMITED{NTP}, $IEEE_FLOAT{NTP}

abstract class $REAL{NTP} < $RATIONAL{NTP}, $LIMITED{NTP}, $IEEE_FLOAT{NTP} is -- This abstraction models those real numbers which correspond to -- representable values using the IEEE 754 floating point representation -- (see also the class abstraction $IEEE_FLOAT). -- The only features defined in this abstraction are mathematical -- constant values - which, however, may be implemented dynamically if so -- required. -- Version 1.1 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 20 Dec 96 kh Original from ICSI Sather distribution -- 21 Dec 00 kh Revised number inheritance graph pi : NTP ; -- This feature is the closest possible approximation to the numeric -- value of pi. e : NTP ; -- This feature is the closest possible approximation to the numeric -- value of the base of natural logarithms. sqrt_2 : NTP ; -- This feature is the closest possible approximation to the square -- root of 2. log_2 : NTP ; -- This feature is the closest possible approximation to the natural -- logarithm of 2. log2_e : NTP ; -- This feature is the closest possible approximation to the value of e -- to the natural logarithm of 2. log10_e : NTP ; -- This feature is the closest possible approximation to the value of e -- to the natural logarithm of 10. log_10 : NTP ; -- This feature is the closest possible approximation to the natural -- logarithm of 10. half_pi : NTP ; -- This feature is the closest possible approximation to the numeric -- value of pi divided by two. Note that the result of adding this value to -- itself or of multiplying it by two are not necessarily the same value as -- pi due to the approximate nature of floating point arithmetic. quarter_pi : NTP ; -- This feature is the closest possible approximation to the numeric -- value of pi divided by four. Note that the result of adding this value to -- itself three times or of multiplying it by four are not necessarily the -- same value as pi due to the approximate nature of floating point -- arithmetic. inv_sqrt_2 : NTP ; -- This feature is the closest possible approximation to the numeric -- inverse of the square root of two. Note that the result if multiplying -- this by the square root of two is not necessarily unity due to the -- approximate nature of floating point arithmetic. inv_pi : NTP ; -- This feature is the closest possible approximation to the numeric -- inverse of pi. Note that the result if multiplying this by pi is not -- necessarily unity due to the approximate nature of floating point -- arithmetic. double_inv_pi : NTP ; -- This feature is the closest possible approximation to twice the -- numeric inverse of pi. Note that the result if multiplying this by twice -- pi is not necessarily unity due to the approximate nature of floating point -- arithmetic. double_sqrt_pi : NTP ; -- This feature is the closest possible approximation to twice the -- numeric inverse of the square root of pi. Note that the result is not -- necessarily the same as the result of calculation given the value pi -- and the square root operation due to the approximate nature of floating -- point arithmetic. half : NTP ; -- This feature is the closest possible representation to the value of -- a half (1/2). Note that this may or may not be exact dependent upon -- which of the implementation options has been chosen by an implementer. scale_by( exp : INT ) : SAME ; -- This feature scales the value of self by the given factor, so that -- the result is self * 2.pow(exp) end ; -- $REAL{NTP}

abstract class $COMPLEX{ETP < $REAL{ETP}, NTP} < $ARITHMETIC{NTP},

abstract class $COMPLEX{ETP < $REAL{ETP}, NTP} < $ARITHMETIC{NTP}, $LIMITED{NTP}, $SIGNED{NTP}, $LOG_OPS{NTP} is -- This abstract class models complex numbers. Complex numbers are -- strictly more general than real numbers. -- -- The right abstraction would be to force real numbers to provide a -- "zero" real part, but this is quite awkward. It is simpler to enforce -- no relationship, which conforms to the way most mathematicians seem to -- actually deal with complex and real numbers. -- Version 1.1 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 20 Dec 96 kh Original from ICSI Sather distribution -- 7 Dec 00 kh Revised number inheritance create( re, im : ETP ) : NTP ; -- This feature creates and returns a complex number with the given -- real and imaginary components. create_real( repart : ETP ) : NTP ; -- This feature creates and returns a complex number with the given -- real component with the imaginary part zero. re : ETP ; -- This feature returns the real component of self. im : ETP ; -- This feature returns the imaginary component of self. magnitude : ETP ; -- This feature returns the absolute magnitude of self. magnitude_squared : ETP ; -- This feature returns the square of the absolute magnitude of self. -- It is a synonym for abs_squared. reciprocal : NTP ; -- This feature returns the multiplicative inverse of self. conjugate : NTP ; -- This feature returns the complex conjugate of self. times( factor : ETP ) : NTP ; -- This feature scales both real and imaginary components of self by -- the given factor. div( divisor : ETP ) : NTP ; -- This feature divides both components of self by the given divisor, -- returning the result. cube_root : NTP ; -- This feature returns the complex cube root of self. is_within( radius : ETP, other : NTP ) : BOOL ; -- This feature returns true if and only if self is within the given -- radius of other. end ; -- $COMPLEX{ETP, NTP}