
Class: QuadFloat
Object

+Magnitude

+ArithmeticValue

+Number

+LimitedPrecisionReal

+QuadFloat
 Package:
 stx:libbasic2
 Category:
 MagnitudeNumbers
 Version:
 rev:
1.34
date: 2019/08/10 15:32:19
 user: cg
 file: QuadFloat.st directory: libbasic2
 module: stx stcclassLibrary: libbasic2
 Author:
 Claus Gittinger
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
Number
Float
ShortFloat
LongFloat
Fraction
FixedPoint
Integer
Complex
FloatArray
DoubleArray
[ttps]
coercing & converting

coerce: aNumber

convert the argument aNumber into an instance of the receiver's class and return it.
constants

NaN

return a quadFloat which represents notaNumber (i.e. an invalid number)

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 Ccompiler here...


infinity

return a quadFloat which represents +INF

negativeInfinity

return a quadFloat which represents INF

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 Ccompiler here...


unity

return the neutral element for multiplication (1.0) as QuadFloat

zero

return the neutral element for addition (0.0) as QuadFloat
error reportng

errorUnsupported

instance creation

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

fromFloat: aFloat

return a new quadFloat, given a float value
usage example(s):
QuadFloat fromFloat:123.0
123.0 asQuadFloat
123 asQuadFloat


fromInteger: anInteger

return a new quadFloat, given an integer value
usage example(s):
QuadFloat fromInteger:123
123 asQuadFloat


fromLongFloat: aFloat

return a new quadFloat, given a long float value
usage example(s):
QuadFloat fromLongFloat:123.0 asLongFloat


fromShortFloat: aShortFloat

return a new quadFloat, given a float value
usage example(s):
QuadFloat fromShortFloat:123.0 asShortFloat

queries

epsilon

return the maximum relative spacing of instances of mySelf
(i.e. the valuedelta of the least significant bit)
usage example(s):

exponentCharacter

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

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


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


radix

answer the radix of a QuadFloat's exponent
This is an IEEE float, which is represented as binary
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

negated

return the receiver negated

rem: aNumber

return the floating point remainder of the receiver and the argument, aNumber
coercing & converting

generality

return the generality value  see ArithmeticValue>>retry:coercing:
comparing

< aNumber

return true, if the argument is greater

= aNumber

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

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

differenceFromQuadFloat: aQuadFloat


equalFromQuadFloat: aQuadFloat

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

lessFromQuadFloat: aQuadFloat

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

productFromQuadFloat: aQuadFloat

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

quotientFromQuadFloat: aQuadFloat

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

sumFromQuadFloat: aQuadFloat

sent when aQuadFloat does not know how to add the receiver, self
error reportng

errorUnsupported

printing

printOn: aStream

a zero mantissa is impossible  except for zero and a few others
queries

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


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


isNaN

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