eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'QuadFloat':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: QuadFloat


Inheritance:

   Object
   |
   +--Magnitude
      |
      +--ArithmeticValue
         |
         +--Number
            |
            +--LimitedPrecisionReal
               |
               +--QuadFloat

Package:
stx:libbasic2
Category:
Magnitude-Numbers
Version:
rev: 1.34 date: 2019/08/10 15:32:19
user: cg
file: QuadFloat.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


QuadFloats represent rational numbers with limited precision
and are mapped to IEEE quadruple precision format (128bit),
also called binary128.

If the underlying cpu supports them natively, the machine format (long double) is
used. Otherwise, a software emulation is done, which is much slower.
Thus only use them, if you really need the additional precision;
if not, use Float (which are doubles) or LongFloats which usually have IEEE extended precision (80bit).

QuadFloats give you definite 128 bit quadruple floats,
thus, code using quadFloats is guaranteed to be portable from one architecture to another.

Representation:
        128bit quadruple IEEE floats (16bytes);
        112 bit mantissa,
        16 bit exponent,
        34 decimal digits (approx.)

On Sparc CPUs, this is a native supported type (long double) and fast;
on x86 CPUs, this is emulated and slow.

Mixed mode arithmetic:
    quadFloat op anyFloat    -> quadFloat
    anyFloat op quadFloat    -> quadFloat

Range and precision of storage formats: see LimitedPrecisionReal >> documentation


Related information:

    Number
    Float
    ShortFloat
    LongFloat
    Fraction
    FixedPoint
    Integer
    Complex
    FloatArray
    DoubleArray
    [ttps]

Class protocol:

coercing & converting
o  coerce: aNumber
convert the argument aNumber into an instance of the receiver's class and return it.

constants
o  NaN
return a quadFloat which represents not-a-Number (i.e. an invalid number)

o  e
return the constant e as quadFloat

usage example(s):

eDigits has enough digits for 128bit IEEE quads

usage example(s):

do not use as a literal constant here - we cannot depend on the underlying C-compiler here...

o  infinity
return a quadFloat which represents +INF

o  negativeInfinity
return a quadFloat which represents -INF

o  pi
return the constant pi as quadFloat

usage example(s):

piDigits has enough digits for 128bit IEEE quads

usage example(s):

do not use as a literal constant here - we cannot depend on the underlying C-compiler here...

o  unity
return the neutral element for multiplication (1.0) as QuadFloat

o  zero
return the neutral element for addition (0.0) as QuadFloat

error reportng
o  errorUnsupported

instance creation
o  basicNew
return a new quadFloat - here we return 0.0
- QuadFloats are usually NOT created this way ...
Its implemented here to allow things like binary store & load
of quadFloats.
(but it is not a good idea to store the bits of a float - the reader might have a
totally different representation - so floats should be
binary stored in a device independent format).

o  fromFloat: aFloat
return a new quadFloat, given a float value

usage example(s):

     QuadFloat fromFloat:123.0
     123.0 asQuadFloat
     123 asQuadFloat

o  fromInteger: anInteger
return a new quadFloat, given an integer value

usage example(s):

     QuadFloat fromInteger:123
     123 asQuadFloat

o  fromLongFloat: aFloat
return a new quadFloat, given a long float value

usage example(s):

     QuadFloat fromLongFloat:123.0 asLongFloat

o  fromShortFloat: aShortFloat
return a new quadFloat, given a float value

usage example(s):

     QuadFloat fromShortFloat:123.0 asShortFloat

queries
o  epsilon
return the maximum relative spacing of instances of mySelf
(i.e. the value-delta of the least significant bit)

usage example(s):

     self epsilon

o  exponentCharacter
return the character used to print between mantissa an exponent.
Also used by the scanner when reading numbers.

o  numBitsInExponent
answer the number of bits in the exponent
the hidden bit is not counted here:

This is an 128bit quadfloat,
where 15 bits are available in the exponent:
seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...

usage example(s):

     1.0 class numBitsInExponent -> 11
     1.0 asShortFloat class numBitsInExponent -> 8
     1.0 asLongFloat class numBitsInExponent -> 15
     1.0 asQuadFloat class numBitsInExponent -> 15

o  numBitsInMantissa
answer the number of bits in the mantissa
the hidden bit is not counted here:

This is an 128bit quadfloat,
where 112 bits are available in the mantissa:
seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...

usage example(s):

     1.0 class numBitsInMantissa
     1.0 asShortFloat class numBitsInMantissa
     1.0 asLongFloat class numBitsInMantissa
     1.0 asQuadFloat class numBitsInMantissa

o  radix
answer the radix of a QuadFloat's exponent
This is an IEEE float, which is represented as binary


Instance protocol:

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  negated
return the receiver negated

o  rem: aNumber
return the floating point remainder of the receiver and the argument, aNumber

coercing & converting
o  generality
return the generality value - see ArithmeticValue>>retry:coercing:

comparing
o  < aNumber
return true, if the argument is greater

o  = aNumber
return true, if the argument represents the same numeric value
as the receiver, false otherwise

o  hash
return a number for hashing; redefined, since floats compare
by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same
as 3 hash.

usage example(s):

     1.2345 hash
     1.2345 asShortFloat hash
     1.2345 asLongFloat hash
     1.2345 asQuadFloat hash

     1.0 hash
     1.0 asShortFloat hash
     1.0 asLongFloat hash
     1.0 asQuadFloat hash

     0.5 asShortFloat hash
     0.5 asShortFloat hash
     0.5 asLongFloat hash
     0.5 asQuadFloat hash

     0.25 asShortFloat hash
     0.25 asShortFloat hash
     0.25 asLongFloat hash
     0.25 asQuadFloat hash

double dispatching
o  differenceFromQuadFloat: aQuadFloat

o  equalFromQuadFloat: aQuadFloat
sent when aQuadFloat does not know how to compare agaist the receiver, self

o  lessFromQuadFloat: aQuadFloat
sent when aQuadFloat does not know how to compare agaist the receiver, self

o  productFromQuadFloat: aQuadFloat
sent when aQuadFloat does not know how to multiply the receiver, self

o  quotientFromQuadFloat: aQuadFloat
sent when aQuadFloat does not know how to multiply the receiver, self

o  sumFromQuadFloat: aQuadFloat
sent when aQuadFloat does not know how to add the receiver, self

error reportng
o  errorUnsupported

printing
o  printOn: aStream
a zero mantissa is impossible - except for zero and a few others

queries
o  isFinite
return true, if the receiver is a finite float
i.e. not NaN and not infinite.

usage example(s):

	1.0 isFinite
	self NaN isFinite
	self infinity isFinite
	self negativeInfinity isFinite
	(0.0 uncheckedDivide: 0.0) isFinite
	(1.0 uncheckedDivide: 0.0) isFinite

o  isInfinite
return true, if the receiver is an infinite float.
i.e. +Inf or -Inf.

usage example(s):

	1.0 isFinite
	1.0 isInfinite
	self NaN isFinite
	self NaN isInfinite
	self infinity isFinite
	self infinity isInfinite
	self negativeInfinity isFinite
	self negativeInfinity isInfinite
	(0.0 uncheckedDivide: 0.0) isFinite
	(1.0 uncheckedDivide: 0.0) isFinite

o  isNaN
return true, if the receiver is a finite float
i.e. not NaN and not infinite.



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Mon, 29 May 2023 11:50:00 GMT