eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'LimitedPrecisionReal':

Home

everywhere
www.exept.de
for:
[back]

Class: LimitedPrecisionReal


Inheritance:

   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

Description:


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
  -------+------------+-----------------------------+---------------------+--------------------+------------------------------    


Related information:

    Fraction
    FixedPoint

Class protocol:

class initialization
o  initialize
initialize ANSI compliant float globals

constants & defaults
o  NaN
return the constant NaN (not a Number).

o  e
return the closest approximation of the irrational number e

** This method raises an error - it must be redefined in concrete classes **

o  emax
return the largest exponent

** This method raises an error - it must be redefined in concrete classes **

o  emin
return the smallest exponent

** This method raises an error - it must be redefined in concrete classes **

o  epsilon
return the maximum relative spacing

o  fmax
return the largest value allowed

** This method raises an error - it must be redefined in concrete classes **

o  fmin
return the minimum value allowed

** This method raises an error - it must be redefined in concrete classes **

o  infinity
return a float representing infinity

o  negativeInfinity
return a float representing negative infinity

o  pi
return the closest approximation of the irrational number pi

** This method raises an error - it must be redefined in concrete classes **

instance creation
o  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.

o  fromLimitedPrecisionReal: anLPReal
return a float with anLPReals value.
You might loose bits when doing this.
Slow fallback.

o  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

o  new: aNumber
catch this message - not allowed for floats/doubles

queries
o  decimalPrecision
return the number of valid decimal digits

o  denormalized
Return whether the instances of this class can
represent values in denormalized format.

o  isAbstract
Return if this class is an abstract class.
True is returned for LimitedPrecisionReal here; false for subclasses.

o  numBitsInExponent
return the number of bits in the exponent

** This method raises an error - it must be redefined in concrete classes **

o  numBitsInIntegerPart

o  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 **

o  precision
return the number of valid mantissa bits

o  radix
return the radix (base)

** This method raises an error - it must be redefined in concrete classes **


Instance protocol:

accessing
o  at: index
redefined to prevent access to individual bytes in a real.

o  at: index put: aValue
redefined to prevent access to individual bytes in a real

arithmetic
o  * aNumber
return the product of the receiver and the argument.

o  + aNumber
return the sum of the receiver and the argument, aNumber

o  - aNumber
return the difference of the receiver and the argument, aNumber

o  / aNumber
return the quotient of the receiver and the argument, aNumber

o  // aNumber
return the integer quotient of dividing the receiver by aNumber with
truncation towards negative infinity.

o  ceiling

o  floor

o  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
o  asFloat

o  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.

o  asInteger
return an integer with same value - might truncate

o  asLargeFloat

o  asLimitedPrecisionReal
return a float of any precision with same value

o  asLongFloat

o  asRational
Answer a Rational number--Integer or Fraction--representing the receiver.
Same as asFraction fro st-80 compatibility.

o  asShortFloat

o  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

o  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

o  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
o  < aNumber
return true, if the argument is greater

copying
o  deepCopy
return a deep copy of myself
- because storing into floats is not recommended/allowed, its ok to return the receiver

o  deepCopyUsing: aDictionary postCopySelector: postCopySelector
return a deep copy of myself
- because storing into floats is not recommended/allowed, its ok to return the receiver

o  shallowCopy
return a shallow copy of the receiver

o  simpleDeepCopy
return a deep copy of the receiver
- because storing into floats is not recommended/allowed, its ok to return the receiver

double dispatching
o  differenceFromFraction: aFraction
sent when a fraction does not know how to subtract the receiver, a float

o  differenceFromTimestamp: aTimestamp
I am to be interpreted as seconds, return the timestamp this number of seconds
before aTimestamp

o  productFromFraction: aFraction
sent when a fraction does not know how to multiply the receiver, a float

o  quotientFromFraction: aFraction
Return the quotient of the argument, aFraction and the receiver.
Sent when aFraction does not know how to divide by the receiver.

o  sumFromFraction: aFraction
sent when a fraction does not know how to add the receiver, a float

o  sumFromTimestamp: aTimestamp
I am to be interpreted as seconds, return the timestamp this number of seconds
after aTimestamp

printing & storing
o  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.

o  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 **

o  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.

o  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
o  defaultNumberOfDigits
Answer how many digits of accuracy this class supports

o  precision
return the number of valid mantissa bits.
Should be redefined in classes which allow per-instance precision specification

o  size
redefined since reals are kludgy (ByteArry)

testing
o  isFinite

** This method raises an error - it must be redefined in concrete classes **

o  isFloat
return true, if the receiver is some kind of floating point number;
false is returned here.
Same as #isLimitedPrecisionReal, but a better name ;-)

o  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 ...

o  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.

o  isNaN

** This method raises an error - it must be redefined in concrete classes **

o  isNegativeZero
many systems have two float.Pnt zeros

o  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 **

o  positive
return true if the receiver is greater or equal to zero

truncation & rounding
o  ceilingAsFloat

o  floorAsFloat

o  roundedAsFloat

o  truncatedAsFloat

visiting
o  acceptVisitor: aVisitor with: aParameter



ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 19:54:56 GMT