|
|
Class: LimitedPrecisionReal
Object
|
+--Magnitude
|
+--ArithmeticValue
|
+--Number
|
+--LimitedPrecisionReal
|
+--Float
|
+--LargeFloat
|
+--LongFloat
|
+--ShortFloat
- Package:
- stx:libbasic
- Category:
- Magnitude-Numbers
- Version:
- rev:
1.72
date: 2010/03/06 11:27:34
- user: cg
- file: LimitedPrecisionReal.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
Abstract superclass for any-precision floating point numbers (i.e. Float and Double).
Due to historic reasons, ST/X's Floats are what Doubles are in ST-80.
This may change soon (implementing LPReal is a first step towards this).
Range and Precision of Storage Formats:
Format | Class | Significant Digits (Binary) | Smallest Pos Number | Largest Pos Number | Significant Digits (Decimal)
-------+------------+-----------------------------+---------------------+--------------------+------------------------------
single | ShortFloat | 24 | 1.175... 10-38 | 3.402... 10+38 | 6-9
-------+------------+-----------------------------+---------------------+--------------------+------------------------------
double | Float | 53 | 2.225... 10-308 | 1.797... 10+308 | 15-17
-------+------------+-----------------------------+---------------------+--------------------+------------------------------
double | LongFloat | 113 | 3.362... 10-4932 | 1.189... 10+4932 | 33-36
ext | | | | |
(SPARC)| | | | |
-------+ |-----------------------------+---------------------+--------------------+------------------------------
double | | 64 | 3.362... 10-4932 | 1.189... 10+4932 | 18-21
ext | | | | |
(x86) | | | | |
-------+------------+-----------------------------+---------------------+--------------------+------------------------------
-- | LargeFloat | arbitrary | arbitrarily small | arbitrarily large | arbitrary
-------+------------+-----------------------------+---------------------+--------------------+------------------------------
Fraction
FixedPoint
class initialization
-
initialize
-
initialize ANSI compliant float globals
constants & defaults
-
NaN
-
return the constant NaN (not a Number).
-
e
-
return the closest approximation of the irrational number e
** This method raises an error - it must be redefined in concrete classes **
-
emax
-
return the largest exponent
** This method raises an error - it must be redefined in concrete classes **
-
emin
-
return the smallest exponent
** This method raises an error - it must be redefined in concrete classes **
-
epsilon
-
return the maximum relative spacing
-
fmax
-
return the largest value allowed
** This method raises an error - it must be redefined in concrete classes **
-
fmin
-
return the minimum value allowed
** This method raises an error - it must be redefined in concrete classes **
-
infinity
-
return a float representing infinity
-
negativeInfinity
-
return a float representing negative infinity
-
pi
-
return the closest approximation of the irrational number pi
** This method raises an error - it must be redefined in concrete classes **
instance creation
-
fromInteger: anInteger
-
return a float with anInteger's value.
Since floats have a limited precision, you usually loose bits when doing this
(see Float decimalPrecision, LongFloat decimalPrecision.
-
fromLimitedPrecisionReal: anLPReal
-
return a float with anLPReals value.
You might loose bits when doing this.
Slow fallback.
-
fromNumerator: numerator denominator: denominator
-
Create a limited precision real from a Rational.
This version will answer the nearest flotaing point value,
according to IEEE 754 round to nearest even default mode
-
new: aNumber
-
catch this message - not allowed for floats/doubles
queries
-
decimalPrecision
-
return the number of valid decimal digits
-
denormalized
-
Return whether the instances of this class can
represent values in denormalized format.
-
isAbstract
-
Return if this class is an abstract class.
True is returned for LimitedPrecisionReal here; false for subclasses.
-
numBitsInExponent
-
return the number of bits in the exponent
** This method raises an error - it must be redefined in concrete classes **
-
numBitsInIntegerPart
-
-
numBitsInMantissa
-
return the number of bits in the mantissa
(typically 1 less than the precision due to the hidden bit)
** This method raises an error - it must be redefined in concrete classes **
-
precision
-
return the number of valid mantissa bits
-
radix
-
return the radix (base)
** This method raises an error - it must be redefined in concrete classes **
accessing
-
at: index
-
redefined to prevent access to individual bytes in a real.
-
at: index put: aValue
-
redefined to prevent access to individual bytes in a real
arithmetic
-
* aNumber
-
return the product of the receiver and the argument.
-
+ aNumber
-
return the sum of the receiver and the argument, aNumber
-
- aNumber
-
return the difference of the receiver and the argument, aNumber
-
/ aNumber
-
return the quotient of the receiver and the argument, aNumber
-
// aNumber
-
return the integer quotient of dividing the receiver by aNumber with
truncation towards negative infinity.
-
ceiling
-
-
floor
-
-
timesTwoPower: anInteger
-
multiply self by a power of two.
Implementation takes care of preserving class and avoiding overflow/underflow
Thanks to Nicolas Cellier for this code
coercing & converting
-
asFloat
-
-
asFraction
-
Answer a rational number (Integer or Fraction) representing the receiver.
This conversion uses the continued fraction method to approximate
a floating point number.
In contrast to #asTrueFraction, which returns exactly the value of the float,
this rounds in the last significant bit of the floating point number.
-
asInteger
-
return an integer with same value - might truncate
-
asLargeFloat
-
-
asLimitedPrecisionReal
-
return a float of any precision with same value
-
asLongFloat
-
-
asRational
-
Answer a Rational number--Integer or Fraction--representing the receiver.
Same as asFraction fro st-80 compatibility.
-
asShortFloat
-
-
asTrueFraction
-
Answer a fraction or integer that EXACTLY represents self,
an any-precision IEEE floating point number, consisting of:
numMantissaBits bits of normalized mantissa (i.e. with hidden leading 1-bit)
optional numExtraBits between mantissa and exponent (normalized flag for ext-real)
numExponentBits bits of 2s complement exponent
1 sign bit.
Taken from Floats asTrueFraction
-
exponent
-
extract a normalized floats exponent.
The returned value depends on the float-representation of
the underlying machine and is therefore highly unportable.
This is not for general use.
This assumes that the mantissa is normalized to
0.5 .. 1.0 and the floats value is mantissa * 2^exp
-
fractionalPart
-
This has been renamed to #fractionPart for ST80 compatibility.
extract the after-decimal fraction part.
the floats value is
float truncated + float fractionalPart
** This is an obsolete interface - do not use it (it may vanish in future versions) **
comparing
-
< aNumber
-
return true, if the argument is greater
copying
-
deepCopy
-
return a deep copy of myself
- because storing into floats is not recommended/allowed, its ok to return the receiver
-
deepCopyUsing: aDictionary postCopySelector: postCopySelector
-
return a deep copy of myself
- because storing into floats is not recommended/allowed, its ok to return the receiver
-
shallowCopy
-
return a shallow copy of the receiver
-
simpleDeepCopy
-
return a deep copy of the receiver
- because storing into floats is not recommended/allowed, its ok to return the receiver
double dispatching
-
differenceFromFraction: aFraction
-
sent when a fraction does not know how to subtract the receiver, a float
-
differenceFromTimestamp: aTimestamp
-
I am to be interpreted as seconds, return the timestamp this number of seconds
before aTimestamp
-
productFromFraction: aFraction
-
sent when a fraction does not know how to multiply the receiver, a float
-
quotientFromFraction: aFraction
-
Return the quotient of the argument, aFraction and the receiver.
Sent when aFraction does not know how to divide by the receiver.
-
sumFromFraction: aFraction
-
sent when a fraction does not know how to add the receiver, a float
-
sumFromTimestamp: aTimestamp
-
I am to be interpreted as seconds, return the timestamp this number of seconds
after aTimestamp
printing & storing
-
printOn: aStream
-
append a printed representation of the receiver to
the argument, aStream.
LimitedPrecisonReal and its subclasses use #printString instead of
#printOn: as basic print mechanism.
-
printString
-
return a printed representation of the receiver
LimitedPrecisonReal and its subclasses use #printString instead of
#printOn: as basic print mechanism.
** This method raises an error - it must be redefined in concrete classes **
-
storeOn: aStream
-
append a printed representation of the receiver to
the argument, aStream.
LimitedPrecisonReal and its subclasses use #storeString instead of
#storeOn: as basic store mechanism.
-
storeString
-
return a printed representation of the receiver
LimitedPrecisonReal and its subclasses use #storeString instead of
#storeOn: as basic print mechanism.
** This method raises an error - it must be redefined in concrete classes **
queries
-
defaultNumberOfDigits
-
Answer how many digits of accuracy this class supports
-
precision
-
return the number of valid mantissa bits.
Should be redefined in classes which allow per-instance precision specification
-
size
-
redefined since reals are kludgy (ByteArry)
testing
-
isFinite
-
** This method raises an error - it must be redefined in concrete classes **
-
isFloat
-
return true, if the receiver is some kind of floating point number;
false is returned here.
Same as #isLimitedPrecisionReal, but a better name ;-)
-
isInfinite
-
return true, if the receiver is an infinite float (Inf).
These are not created by ST/X float operations (they raise an exception);
however, inline C-code could produce them ...
-
isLimitedPrecisionReal
-
return true, if the receiver is some kind of limited precision real (i.e. floating point) number;
true is returned here - the method is redefined from Object.
-
isNaN
-
** This method raises an error - it must be redefined in concrete classes **
-
isNegativeZero
-
many systems have two float.Pnt zeros
-
numberOfBits
-
return the size (in bits) of the real;
typically, this is 64 for Floats and 32 for ShortFloats,
but who knows ...
** This method raises an error - it must be redefined in concrete classes **
-
positive
-
return true if the receiver is greater or equal to zero
truncation & rounding
-
ceilingAsFloat
-
-
floorAsFloat
-
-
roundedAsFloat
-
-
truncatedAsFloat
-
visiting
-
acceptVisitor: aVisitor with: aParameter
-
|