concepts.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 $NFE{NTP} < $ORDERED{NTP}, $BINARY, $TEXT

abstract class $NFE{NTP} < $ORDERED{NTP}, $BINARY, $TEXT is -- This abstract class is defined over numeric field elements. Because -- of contravariance, parameterisation over NTP (the concrete numeric type) -- which is the type of the argument to many of the defined routines is -- required. -- -- NOTE The creation operations are included for all numeric types -- except MONEY! Note, however, MONEY does offer creation -- from all numeric values. See also class $CONVERSION. -- 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 -- 6 Dec 00 kh Revised number inheritance graph create( val : CARD ) : NTP ; -- This routine creates a number from the cardinal value parameter, -- provided that val is also a member of the target number domain, otherwise -- void. create( val : FIELD ) : NTP ; -- This routine creates a number from the field number value parameter, -- provided that val is also a member of the target number domain, otherwise -- void. create( val : INT ) : NTP ; -- This routine creates a number from the integer value parameter, -- provided that val is also a member of the target number domain, otherwise -- void. create( val : INTI ) : NTP ; -- This routine creates a number from the infinite integer value -- parameter, provided that val is also a member of the target number domain, -- otherwise void. create( val : RAT ) : NTP ; -- This routine creates a number from the rational value parameter, -- provided that val is also a member of the target number domain, otherwise -- void. create( val : FLT ) : NTP ; -- This routine creates a number from the floating point value parameter, -- provided that val is also a member of the target number domain, otherwise -- void. create( val : FLTD ) : NTP ; -- This routine creates a number from the floating point value parameter, -- provided that val is also a member of the target number domain, otherwise -- void. is_exact : BOOL ; -- This feature returns true if and only if the value of self is an -- exact whole number. is_limited : BOOL ; -- This feature returns true if and only if the domain of NTP is finite. is_signed : BOOL ; -- This feature returns true if and only if the domain of NTP includes -- values below zero. is_pos : BOOL ; -- This feature returns true if and only if self is greater than zero. one : NTP ; -- This returns a value which is numerically one greater than the value -- zero in the appropriate number representation. abs : NTP ; -- This routine returns the absolute value of self providing that that -- is representable in the appropriate number domain. sign : NUM_SIGNS ; -- This feature returns the signed state of self - Negative, Zero or -- Positive. end ; -- $NFE

abstract class $ZERO{NTP < $NFE{NTP}}

abstract class $ZERO{NTP < $NFE{NTP}} is -- This abstract class models the concept of the value zero. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 20 Dec 00 kh Original for number inheritance revision is_zero : BOOL ; -- This feature returns true if and only if self is exactly zero. zero : NTP ; -- This returns the value zero in the appropriate number representation. end ; -- $ZERO

abstract class $ADD_OPS{NTP < $NFE{NTP}}

abstract class $ADD_OPS{NTP < $NFE{NTP}} is -- This abstract class models the concept of addition and subtraction. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 20 Dec 00 kh Original for number inheritance revision plus( other : NTP ) : NTP ; -- This routine returns the value which is the sum of self and other, -- provided that that is representable in the appropriate number domain. minus( other : NTP ) : NTP ; -- This routine returns the value which is the arithmetic difference -- between self and other, provided that that is representable in the -- appropriate number domain. end ; -- $ADD_OPS

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

abstract class $CONVERSION{NTP < $NFE{NTP}} is -- This class is an abstraction over numbers which have values which -- can be represented in another numeric class domain. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 6 Dec 00 kh Original for number inheritance revision card : CARD ; -- This feature returns the value of self as an unsigned exact number, -- providing that self is an exact number value within the range -- CARD::maxval to CARD::minval. field : FIELD ; -- This feature returns the value of self as a closed field number, -- providing that self is an exact number value. int : INT ; -- This feature returns the value of self as a signed exact number, -- providing that self is an exact number value and within the range -- INT::maxval to INT::minval. inti : INTI ; -- This feature returns the value of self as an infinite precision -- integer - rounded towards the nearest integral value. rat : RAT ; -- This feature returns the value of self as a rational number. flt : FLT ; -- This feature returns the value of self as a floating point number. If -- the value is not representable as a floating point number then infinity -- is to be returned. fltd : FLTD ; -- This feature returns the value of self as a double floating point -- number. If the value is not representable then infinity is to be returned. end ; -- $CONVERSION

abstract class $ARITHMETIC{NTP} < $NFE{NTP}, $ZERO{NTP}, $ADD_OPS{NTP}

abstract class $ARITHMETIC{NTP} < $NFE{NTP}, $ZERO{NTP}, $ADD_OPS{NTP} is -- This class is an abstraction over numbers for which multiplicative operations in the range and domain of NTP are meaningful. -- NOTE This excludes classes for which self-multiplication is meaningless -- (eg money). -- 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 -- 6 Dec 00 kh Revised for numeric inheritance changes times( other : NTP ) : NTP ; -- This routine returns the value which is the product of self and other, -- provided that that is representable in the appropriate number domain. div( other : NTP ) : NTP ; -- This routine returns the value which is the quotient obtained by -- dividing self by other, provided that that is representable in the -- appropriate number domain. mod( other : NTP ) : NTP ; -- This feature returns the unsigned remainder of self with respect to -- other - this is identically zero for real numbers. An exception shall -- be raised when other is 0. square : NTP ; -- This feature returns the value which is the result of multiplying -- self by self, provided that this is representable, otherwise nil. cube : NTP ; -- This feature returns the result of multiplying self by self and the -- result of that evaluation by self again. sqrt : NTP ; -- This routine returns the value which is the square root of self. end ; -- $ARITHMETIC{NTP}

abstract class $LIMITED{NTP < $NFE{NTP}}

abstract class $LIMITED{NTP < $NFE{NTP}} is -- This class is an abstraction over number classes the range of values -- of which are limited by the computer representation. -- 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 maxval : NTP ; -- This feature returns the maximum value representable in the -- implementation of this class. minval : NTP ; -- This feature returns the minimum value representable in the -- implementation of this class. num_chars : CARD ; -- This feature returns the number of characters required in a textual -- representation of self. end ; -- $LIMITED{NTP}

abstract class $SIGNED{NTP < $NFE{NTP}}

abstract class $SIGNED{NTP < $NFE{NTP}} is -- This class is an abstraction over the domain of signed number classes -- for which values may be less than zero. -- Version 1.1 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 5 Jan 97 kh Original provided when separating exact -- arithmetic classes -- 6 Dec 00 kh Revised number inheritance graph negate : NTP ; -- This routine returns the negation of self provided that this is -- representable in the value domain. Note that this is an implementation -- issue dependent upon the numeric model designed into the CPU -- eg if -- it is twos-complement then it is not possible to negate the minimum -- value. negatable : BOOL ; -- This routine returns true if and only if the negated value of -- self is within the value domain of the class NTP. is_neg : BOOL ; -- This feature returns true if and only if the number is negative. end ; -- $SIGNED{NTP}

abstract class $COUNTS{NTP < $NFE{NTP}}

abstract class $COUNTS{NTP < $NFE{NTP}} is -- This class is an abstraction over exact number classes which provide -- counting features. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 20 Dec 00 kh Original for number inheritance revision times! ; -- This iter feature yields self times without returning a value. times! : NTP ; -- This iter feature yields successive values from one up to the value -- of self. end ; -- $COUNTS{NTP}

abstract class $SEQUENCERS{NTP < $ARITHMETIC{NTP}}

abstract class $SEQUENCERS{NTP < $ARITHMETIC{NTP}} is -- This class is an abstraction over exact number classes which provide -- sequencing features. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 6 Dec 00 kh Original for number inheritance revision for!( once cnt : NTP ) : NTP ; -- This iter feature yields cnt successive values starting with self. -- It is an error if an attempt is made to yield a value larger than maxval; -- an exception shall be raised if this should occur. up! : NTP ; -- This iter feature yields successive numbers from self upwards. It is -- an error if an attempt is made to yield a value larger than maxval; -- an exception shall be raised if this should occur. upto!( once limit : NTP ) : NTP ; -- This iter feature yields successive numbers from self up to the given -- limit. downto!( once limit : NTP ) : NTP ; -- This iter feature yields successively smaller numbers from self down -- to the given limit. step!( once cnt : CARD, once interval : INT ) : NTP ; -- This iter feature yields cnt numbers starting with the value of self, -- each differing from the preceding value by the given interval. stepto!( once finish : NTP, once interval : INT ) : NTP ; -- This iter feature yields successive values from self up to finish, -- each value being the value of the preceding yield offset by the given -- interval. end ; -- $SEQUENCERS{NTP}

abstract class $ROUNDING{NTP < $NFE{NTP}}

abstract class $ROUNDING{NTP < $NFE{NTP}} is -- This class is an abstraction over number classes the range of values -- of which are limited by the computer representation. -- 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 floor : NTP ; -- This feature returns the highest integral value which is less -- than self. ceiling : NTP ; -- This feature returns the lowest integral value which is greater -- than self. round : NTP ; -- This feature returns the result of rounding self to the nearest -- integral value. truncate : NTP ; -- This feature returns the result of discarding any fractional part -- of the value of self. end ; -- $ROUNDING{NTP}

abstract class $VALUE_ITERS{NTP < $NFE{NTP}}

abstract class $VALUE_ITERS{NTP < $NFE{NTP}} is -- This class is an abstraction over number classes which provide -- for value iteration features. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 6 Dec 00 kh Original for number inheritance revision sum!( other : NTP ) : SAME ; -- This iter feature yields the sum of all previous values of other. -- Note that other is re-evaluated on each re-entry of the iter. Dependent -- on the value provided, this iter may therefore produce a non-representable -- value which shall cause an exception to be raised. product!( other : NTP ) : SAME ; -- This iter feature yields the product of all previous values of -- other. Note that other is re-evaluated on each re-entry of the iter. -- Dependent on the value provided, this iter may therefore produce a -- non-representable value which shall cause an exception to be raised. end ; -- $VALUE_ITERS{NTP}

abstract class $IEEE_FLOAT{NTP < $REAL{NTP}}

abstract class $IEEE_FLOAT{NTP < $REAL{NTP}} is -- This abstraction defines a model of the IEEE 754 standard -- specification. -- 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 min_exp : INT ; -- This feature is the minimum negative integer x such that b^(x-1) is -- in the range of normalized floating point numbers. min_exp10 : INT ; -- This feature is the minimum negative integer x such that 10^x is in -- the range of normalized floating point numbers. max_exp : INT ; -- This feature is the maximum permissible binary exponent value for -- numbers of this class max_exp10 : INT ; -- This feature is the maximum integer value x s.t 10^x is in the range -- of values in this class. epsilon : NTP ; -- This feature is the minimum positive value x s.t 1.0 + x /= x digits : INT ; -- This feature is the number of decimal digits of precision for values -- in this class. mantissa_bits : INT ; -- This feature is the number of bits in the significand, including the -- implied bit referrred to in the specification. Max_Precision : CARD ; -- This feature is the number of decimal digits in a number above which -- rounding problems occur in arithmetic operations. Num_Bits : CARD ; -- This feature is the total number of binary digits in the representation of values of this class. is_nan : BOOL ; -- This returns true if and only if self is not the representation of -- a number in the real number value domain, otherwise false. quiet_NaN( sig : INT ) : NTP ; -- This routine returns the representation which is interpreted by -- the IEEE arithmetic model as being a quiet (ie non-interrupting) NaN. -- The argument is not used in this implementation. Built-in to this -- implementation. signalling_NaN( sig : INT ) : NTP ; -- This routine returns the representation which is interpreted by -- the IEEE arithmetic model as a signalling (ie interrupt generating) NaN. -- The argument is unused in this implementation. infinity : NTP ; -- This routine returns the representation of infinity -- which is -- implementation-dependent. min_normal : NTP ; -- This routine returns the smallest normalized positive number -- in this class. max_normal : NTP ; -- This routine returns the largest normalized positive number -- in this class. min_subnormal : NTP ; -- This routine returns the smallest un-normalized positive number -- in this class. max_subnormal : NTP ; -- This routine returns the largest un-normalized positive number -- in this class. is_normal : BOOL ; -- This predicate returns true if and only if self is a normalised -- number. Built-in to this implementation. is_subnormal : BOOL ; -- This predicate returns true if and only if self is an un-normalised -- number. signbit_set : BOOL ; -- This predicate returns true if and only if the sign bit of self is -- set. The number, however, can be one of the special values in addition -- to being a negative number if this is set. is_finite : BOOL ; -- This predicate returns true if and only if self is zero, subnormal -- or normal. is_inf : BOOL ; -- This predicate returns true if and only if self is infinite. unbiassed_exponent : INT ; -- This routine returns the unbiassed exponent of self. -- -- NOTE The IEEE 754 standard specifies that exponent storage shall be -- unsigned - being given an offset or bias in order to achieve this. copysign( other : NTP ) : NTP ; -- This routine returns self with the sign bit set to be the same as -- the sign bit of other. This routine is provided to overcome some of -- the limitations of certain IEEE 754 implementations which have two values -- of zero - in order to make comparison for zero possible. nextup : NTP ; -- This routine returns the value in the IEEE model number domain which -- is the successor in that domain of the value of self. nextdown : NTP ; -- This routine returns the value in the IEEE model number domain which -- is the predecessor in that domain of the value of self. -- get_representation( -- out sign : BOOL, -- out exp : INT, -- out mantissa : INT -- ) ; -- This routine splits up the floating point coding into its sign, -- exponent and mantissa components which are returned in the arguments. -- BECAUSE OF DIFFERING MANTISSA SIZES THIS CANNOT BE IN THE ABSTRACTION!! remainder( other : NTP ) : NTP ; -- This feature returns a remainder of self with respect to other; that -- is, the result is one of the numbers that differs from self by an integral -- multiple of other -- '(self - result)/other' is an integral value. end ; -- $IEEE_FLOAT{NTP}

abstract class $LOG_OPS{NTP < $NFE{NTP}}

abstract class $LOG_OPS{NTP < $NFE{NTP}} is -- This abstraction has been separated from $REAL_NUMBER in the original -- distribution of Sather. -- Version 1.1 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 10 Jun 98 kh Original from ICSI Sather dist -- 20 Dec 00 kh Modified for revised inheritance graph pow( exp : NTP ) : NTP ; -- This feature returns self to the power exp, providing that the result -- is representable, otherwise it shall return nil! exp : NTP ; -- This routine returns the value of e raised to the power of self. log : NTP ; -- This routine returns the natural logarithm of self (to the base e). end ; -- $LOG_OPS{NTP}

immutable class NUM_SIGNS < $ENUMS{NUM_SIGNS}

immutable class NUM_SIGNS < $ENUMS{NUM_SIGNS} is -- This class implements the concept of the sign of a numeric value -- which may be either positive, negative or zero. -- Version 1.0 Dec 2000. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 6 Dec 00 kh Original when simplifying number classes include ENUM{NUM_SIGNS} ; private const val_count : CARD := 3 ; -- The following constant 'routines' specify the enumeration values. Negative : SAME is return enum(1) end ; Zero : SAME is return enum(2) end ; Positive : SAME is return enum(3) end ; end ; -- NUM_SIGNS