|
Class: LongFloat
Object
|
+--Magnitude
|
+--ArithmeticValue
|
+--Number
|
+--LimitedPrecisionReal
|
+--LongFloat
- Package:
- stx:libbasic
- Category:
- Magnitude-Numbers
- Version:
- rev:
1.289
date: 2023/09/12 13:00:01
- user: cg
- file: LongFloat.st directory: libbasic
- module: stx stc-classLibrary: libbasic
LongFloats represent rational numbers with limited precision.
They use the C-compiler's 'long double' format,
which is either mapped to the IEEE extended precision (80bit)
or IEEE quadruple precision format (128bit),
or (if not supported by the underlying CPU), to regular (double precision) IEEE doubles.
In contrast to Floats (which use the C-compilers 64bit 'double' format),
LongFloats give you one of
80 bit extended floats,
96 bit extended floats
or 128 bit quadruple floats,
depending on the underlying CPU.
Thus, code using longFloats is not guaranteed to be portable from one architecture to another,
but faster than software emulations.
NOTE:
on systems which do not support 'long doubles', LongFloats are (silently)
represented as 'doubles'.
ALSO NOTE:
on some machines (i.e. x86/x86_64), the long double format is slightly different
from the standard IEEE format, in that the normally hidden highest bit is
present and visible.
Thus be careful, when exchanging binary data between different CPU architectures.
AND ALSO NOTE:
not all math operations are provided by all architecture's C libraries.
For example, the Windows math libs seem to not provide the inverse hyperbolic
functions (asinh and friends), whereas the MINGW libraries do.
These will fallback to slower inherited functions (which do taylor or power
series computations).
As a general advice: only use this, if you really need to,
and think about alternatives if you need to be super portable
(although, most machinesa are x86 based, these days, and the old borland 32 bit
STX version is going to be obsoleted sooner or later anyway).
Representation:
gcc-x86:
80bit extended IEEE floats stored in in 96bits (12bytes);
1 bit integer part,
64 bit mantissa,
16 bit exponent,
19 decimal digits (approx.)
borland-x86 (WIN32):
80bit extended IEEE floats stored in in 80bits (10bytes);
1 bit integer part,
64 bit mantissa,
16 bit exponent,
19 decimal digits (approx.)
gcc-x86_64: (WIN64)
like gcc-x86
gcc-sparc:
128bit quadruple IEEE floats (16bytes);
112 bit mantissa,
16 bit exponent,
34 decimal digits (approx.)
Mixed mode arithmetic:
longFloat op longFloat -> longFloat
longFloat op fix -> longFloat
longFloat op fraction -> longFloat
longFloat op integer -> longFloat
longFloat op shortFloat -> longFloat
longFloat op float -> longFloat
longFloat op complex -> complex
Range and precision of storage formats: see LimitedPrecisionReal >> documentation
[aliases:]
FloatQ (ANSI)
Float80
copyrightCOPYRIGHT (c) 1999 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
accessing
-
defaultPrintFormat
-
'.19' by default, I will print up to 19 digits
-
defaultPrintFormat: aFormatString
-
the formatString must be of the form '.n'.
class initialization
-
initialize
-
print up to 19 valid digits
Usage example(s):
Epsilon := nil.
self initialize.
Epsilon -> 1.08420e-19
|
coercing & converting
-
coerce: aNumber
-
convert the argument aNumber into an instance of the receiver's class and return it.
constants
-
NaN
-
return a longFloat which represents not-a-Number (i.e. an invalid number)
Usage example(s):
whereas all others return a positive NaN
|
Usage example(s):
-
e
-
return the constant e as LongFloat
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...
|
Usage example(s):
Modified (format): / 06-06-2019 / 17:02:27 / Claus Gittinger
|
-
halfPi
-
return the constant pi/2 as LongFloat
Usage example(s):
-
halfPiNegative
-
return the constant -pi/2 as LongFloat
Usage example(s):
-
infinity
-
return a longFloat which represents positive infinity (for my instances).
Warning: do not compare equal against infinities;
instead, check using isFinite or isInfinite
Usage example(s):
-
negativeInfinity
-
return a longFloat which represents positive infinity (for my instances).
Warning: do not compare equal against infinities;
instead, check using isFinite or isInfinite
Usage example(s):
LongFloat negativeInfinity
|
-
phi
-
return the constant phi as LongFloat
Usage example(s):
phiDigits has enough digits for 128bit IEEE quads
|
-
pi
-
return the constant pi as LongFloat
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...
|
-
sqrt2
-
return the constant sqrt(2) as LongFloat
Usage example(s):
sqrt2Digits has enough digits for 128bit IEEE quads
|
Usage example(s):
LongFloat sqrt2 -> 1.414213562373095049
|
-
sqrt3
-
return the constant sqrt(3) as LongFloat
Usage example(s):
sqrt3Digits has enough digits for 128bit IEEE quads
|
Usage example(s):
LongFloat sqrt3 -> 1.732050807568877294
|
-
unity
-
return the neutral element for multiplication (1.0) as LongFloat
-
zero
-
return the neutral element for addition (0.0) as LongFloat
instance creation
-
basicNew
-
return a new longFloat - here we return 0.0
- LongFloats are usually NOT created this way ...
Its implemented here to allow things like binary store & load
of longFloats. (but even this support will go away eventually, its not
a good idea to store the bits of a float - the reader might have a
totally different representation - so floats will eventually be
binary stored in a device independent format.
-
fastFromString: aString at: startIndex
-
return the next LongFloat from the string starting at startIndex.
No spaces are skipped.
Raises an exception, if the startIndex is not valid.
Returns garbage if the argument string is not a valid long double float number.
This is a specially tuned entry (using a low-level C-call to strtold).
It has been added to allow high speed string decomposition
into numbers, especially for mass-data (reading millions of floats).
Usage example(s):
LongFloat fastFromString:'123.45' at:1
LongFloat fastFromString:'123.45' at:2
LongFloat fastFromString:'123.45' at:3
LongFloat fastFromString:'123.45' at:4
LongFloat fastFromString:'123.45' at:5
LongFloat fastFromString:'123.45' at:6
LongFloat fastFromString:'123.45E4' at:1
LongFloat fastFromString:'hello123.45E4' at:6
LongFloat fastFromString:'12345' at:1
LongFloat fastFromString:'12345' at:2
LongFloat fastFromString:'12345' at:3
LongFloat fastFromString:'12345' at:4
LongFloat fastFromString:'12345' at:5
LongFloat fastFromString:'12345' at:6 -> error
LongFloat fastFromString:'12345' at:0 -> error
LongFloat fastFromString:'hello123.45E4' at:1 -> 0
LongFloat fastFromString:'1.7976931348623157e+308'
LongFloat fastFromString:'Nan'
LongFloat fastFromString:'+Inf'
LongFloat fastFromString:'-Inf'
|
Usage example(s):
(Time toRun:[
1000000 timesRepeat:[
LongFloat fastFromString:'123.45' at:1
]
]) / 1000000 185ns 188ns
|
-
fromBytes: bytes exponentSize: exponentSize
-
-
fromFloat: aFloat
-
return a new longFloat, given a float value
Usage example(s):
LongFloat fromFloat:123.0
123.0 asLongFloat
123 asLongFloat
|
-
fromIEEE32Bit: anInteger
-
creates a long float, given the four native float bytes as an integer
Usage example(s):
LongFloat fromIEEE32Bit:((ShortFloat pi digitBytesMSB:true) asIntegerMSB:true)
|
-
fromIEEE64Bit: anInteger
-
creates a long double, given the eight native double bytes as an integer
Usage example(s):
LongFloat fromIEEE64Bit:((Float pi digitBytesMSB:true) asIntegerMSB:true)
|
-
fromInteger: anInteger
-
return a new longFloat, given an integer value
Usage example(s):
LongFloat fromInteger:123
LongFloat fromInteger:(100 factorial)
(100 factorial) asLongFloat
|
-
fromShortFloat: aFloat
-
return a new longFloat, given a shortFloat value
Usage example(s):
LongFloat fromShortFloat:(123.0 asShortFloat)
LongFloat fromShortFloat:122
|
queries
-
defaultPrintPrecision
-
the default number of digits when printing
Usage example(s):
LongFloat defaultPrintPrecision
ShortFloat defaultPrintPrecision
Float defaultPrintPrecision
|
-
defaultPrintfPrecision
-
the default number of digits when printing with printf's %f format.
Notice, that the C-language standard states that this should be 6;
however, we can adjust it on a per-class basis.
-
emax
-
The largest exponent value allowed by instances of this class.
Usage example(s):
1.0 asLongFloat fmax -> 1.189731495357231765E+4932
1.0 asLongFloat fmin -> 3.362103143112093506E-4932
1.0 asLongFloat emin -> -16382
1.0 asLongFloat emax -> 16383
1.0 asLongFloat eBias -> 16383
|
-
emin
-
The smallest exponent value allowed by instances of this class.
Usage example(s):
1.0 asLongFloat fmax -> 1.189731495357231765E+4932
1.0 asLongFloat fmin -> 3.362103143112093506E-4932
1.0 asLongFloat emin -> -16382
|
-
epsilon
-
return the maximum relative spacing of instances of mySelf
(i.e. the value-delta of the least significant bit)
according to ISO C standard;
Ada, C, C++ and Python language constants;
Mathematica, MATLAB and Octave; and various textbooks
see https://en.wikipedia.org/wiki/Machine_epsilon
-
exponentCharacter
-
return the character used to print between mantissa an exponent.
Also used by the scanner when reading numbers.
-
fmax
-
The largest value allowed by instances of this class.
Usage example(s):
1.0 asLongFloat fmax -> 1.189731495357231765E+4932
LongFloat fmax -> 1.189731495357231765E+4932
|
-
fmin
-
The smallest normalized non-zero value allowed by instances of this class.
Usage example(s):
LongFloat fmax -> 1.189731495357231765E+4932
LongFloat fmin -> 3.362103143112093506e-4932
1.0 asLongFloat fmax -> 1.189731495357231765E+4932
1.0 asLongFloat fmin -> 3.362103143112093506e-4932
|
-
fminDenormalized
-
The smallest non-zero value allowed by denormalized instances of this class.
Usage example(s):
Usage example(s):
LongFloat fmin -> 3.362103143112093506E-4932
LongFloat fminDenormalized -> 0.000000000000000004e-4933
|
-
isBuiltInClass
-
return true if this class is known by the run-time-system.
Here, true is returned for myself, false for subclasses.
-
numBitsInExponent
-
answer the number of bits in the exponent
i386: This is an 80bit longfloat stored in 96 bits (upper 16 bits are unused),
where 15 bits are available in the exponent (i bit is ignored):
00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
x86_64: This is an 80bit longfloat stored in 128 bits (upper 48 bits are unused),
where 15 bits are available in the exponent:
00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
sparc & others: This is an 128bit longfloat,
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 asLongFloat numBitsInExponent -> 15
|
-
numBitsInMantissa
-
answer the number of bits in the mantissa (the significant)
Any hidden bit is not counted here,
If the CPU uses unnormalized floats (x86-FPU), numBitsInMantissa will be the same as precision;
otherwise, the hidden bit is not counted here and precision will be numBitsInMantissa + 1.
i386 / x86_64: This is an 80bit longfloat stored in 80, 96 or 128 bits, depending on the compiler
(upper bits are unused),
the mantissa is unnormalized:
00000000 ... 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
sparc: This is an 128bit longfloat,
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 52 (+1 hidden)
1.0 asShortFloat class numBitsInMantissa 23 (+1 hidden)
1.0 asLongFloat class numBitsInMantissa 64 no hidden
|
Usage example(s):
1.0 asLongFloat numBitsInExponent 15
1.0 asLongFloat numBitsInMantissa 64
1.0 asLongFloat precision 64
1.0 asLongFloat decimalPrecision 19
1.0 asLongFloat eBias 16383
1.0 asLongFloat emin -16382
1.0 asLongFloat emax 16383
1.0 asLongFloat fmin
1.0 asLongFloat fmax 1.189731495357231765E+4932
|
-
numHiddenBits
-
answer the number of hidden bits in the mantissa.
This will return 0 or 1; 0 if there is no hidden bit, 1 if there is.
See https://en.wikipedia.org/wiki/Extended_precision.
i386 / x86_64: This is an 80bit longfloat stored in 80, 96 or 128 bits, depending on the compiler
(upper bits are unused),
the mantissa is unnormalized:
00000000 ... 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
sparc & others: This is an 128bit quadruple float,
where 112 bits are available in the normalized mantissa:
seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm...
Usage example(s):
LongFloat numHiddenBits
1.0 asLongFloat numHiddenBits
1.0 asFloat numHiddenBits
1.0 asShortFloat numHiddenBits
|
-
radix
-
answer the radix of a LongFloat'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
-
abs
-
return the absolute value of the receiver
reimplemented here for speed
Usage example(s):
3.0 asLongFloat abs
-3.0 asLongFloat abs
|
-
negated
-
return myself negated
Usage example(s):
0 negated
0.0 negated
0.0 asLongFloat negated
|
-
rem: aNumber
-
return the floating point remainder of the receiver and the argument, aNumber
-
uncheckedDivide: aNumber
-
return the quotient of the receiver and the argument, aNumber.
Do not check for divide by zero (return NaN or Infinity).
This operation is provided for emulators of other languages/semantics,
where no exception is raised for these results (i.e. Java).
It is only defined if the argument's type is the same as the receiver's.
Usage example(s):
0.0 asLongFloat uncheckedDivide:0
1.0 asLongFloat uncheckedDivide:0.0
-1.0 asLongFloat uncheckedDivide:0.0
|
coercing & converting
-
asFloat
-
return a Float (i.e. an IEEE double) with same value as the receiver.
Does NOT raise an error if the receiver exceeds the float range or is non-finite.
Usage example(s):
1q1000 asFloatChecked -> error
-1q1000 asFloatChecked -> error
1q-1000 asFloatChecked -> error
-1q-1000 asFloatChecked -> error
1q1000 asFloat -> inf
1q-1000 asFloat -> 0.0
-1q1000 asFloat -> -inf
-1q-1000 asFloat -> -0.0
|
-
asFloatChecked
-
Convert to a IEEE 754 double precision floating point.
Raises an error if the result cannot be represented as a float or is non-finite.
If the error is proceeded, you'll get a NaN or Inf
-
asInteger
-
return an integer with same value - might truncate
Usage example(s):
12345.0 asLongFloat asInteger
1e15 asLongFloat asInteger
|
-
asLongFloat
-
return a LongFloat with same value as the receiver - that's me
-
asQDouble
( an extension from the stx:libbasic2 package )
-
return a QDouble with my value
Usage example(s):
1.0 asLongFloat asQDouble
1q100 asLongFloat asQDouble
1q1000 asQDouble
|
-
asQuadFloat
( an extension from the stx:libbasic2 package )
-
return a QuadFloat with same value as the receiver
-
asShortFloat
-
return a ShortFloat with same value as the receiver.
Does NOT raise any error if the receiver exceeds the short float range.
-
asShortFloatChecked
-
return a ShortFloat with same value as the receiver.
Raises an error if the receiver exceeds the short float range or is non-finite.
If the error is proceeded, you'll get a NaN or Inf.
-
generality
-
return the generality value - see ArithmeticValue>>retry:coercing:
comparing
-
< aNumber
-
return true, if the argument is greater
Usage example(s):
10.0 asLongFloat < 10
10.0 asLongFloat < 10.0
10.0 asLongFloat < 10.0 asLongFloat
(10.0 asLongFloat nextFloat:-1) < 10
(10.0 asLongFloat nextFloat:-1) < 10.0
(10.0 asLongFloat nextFloat:-1) < 10.0 asLongFloat
(1.0 asLongFloat nextFloat:-1) < 1.0 false
(1.0 asLongFloat nextFloat:-1) = 1.0 false
(1.0 asLongFloat nextFloat:-1) > 1.0 false
10.0 asLongFloat > 10
10.0 asLongFloat > 10.0
10.0 asLongFloat > 10.0 asLongFloat
1.0 asLongFloat > (1/3)
1.0 asLongFloat > (1/3) asLongFloat
|
-
<= aNumber
-
return true, if the argument is greater or equal
-
= aNumber
-
return true, if the argument represents the same numeric value
as the receiver, false otherwise
-
> aNumber
-
return true, if the argument is less
-
>= aNumber
-
return true, if the argument is less or equal
-
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 asLongFloat hash
1 hash
1.0 hash
1.0 asLongFloat hash
|
-
isAlmostEqualTo: aNumber nEpsilon: nE
-
return true, if the argument, aNumber represents almost the same numeric value
as the receiver, false otherwise.
nE is the number of minimal float distances, that the numbers may differ and
still be considered equal.
For background information why floats need this
read: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
Usage example(s):
67329.234q isAlmostEqualTo:67329.234q + self epsilon nEpsilon:1
1.0 asLongFloat isAlmostEqualTo:1.0001 nEpsilon:1
1.0 asLongFloat isAlmostEqualTo:-1.0 nEpsilon:1
1.0 asLongFloat isAlmostEqualTo:1 nEpsilon:1
0.0 asLongFloat isAlmostEqualTo:0 nEpsilon:1
0.0 asLongFloat isAlmostEqualTo:self epsilon nEpsilon:1
|
-
~= aNumber
-
return true, if the arguments value are not equal.
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
-
productFromInteger: anInteger
-
sent when an integer does not know how to multiply the receiver, self
-
quotientFromFloat: aFloat
-
Return the quotient of the argument, aFloat and the receiver.
Sent when aFloat does not know how to divide by the receiver.
Return aFloat / self
-
raisedFromFloat: aFloat
-
aFloat does not know how to be raised to the receiver
-
sumFromInteger: anInteger
-
sent when an integer does not know how to add the receiver, self
mathematical functions
-
cbrt
-
return the cubic root of myself.
Usage example(s):
8 cbrt
-8 cbrt
8.0 cbrt
-8.0 cbrt
8.0q cbrt
-8.0q cbrt
(8.0q cbrt raisedTo:3)
(-8.0q cbrt raisedTo:3)
8.0 raisedTo:(1/3)
-8.0 raisedTo:(1/3)
|
-
erf
-
return the error function of myself.
Usage example(s):
-
exp
-
return e raised to the power of the receiver
-
gamma
-
return the gamma function value of myself.
Usage example(s):
172 gamma => inf
172q gamma => 1.241018070217667861e+309
|
-
ln
-
return the natural logarithm of myself.
Raises an exception, if the receiver is less or equal to zero.
-
log10
-
return the base-10 logarithm of the receiver.
Raises an exception, if the receiver is less or equal to zero.
-
raisedTo: aNumber
-
return self raised to the power of aNumber
-
sqrt
-
return the square root of myself.
Raises an exception, if the receiver is less than zero.
Usage example(s):
10 asLongFloat sqrt
-10 asLongFloat sqrt
|
printing & storing
-
printOn: aStream
-
append a printed representation of the receiver to
the argument, aStream.
I 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.
Usage example(s):
1.23456789 printString. '1.23456789'
1.23456789 asLongFloat printString. '1.23456788999999989'
1.23456789 asQuadFloat printString. '1.234570'
1.23456789 asOctaFloat printString. '1.234570'
LongFloat pi printString.
1.234 asLongFloat printString.
1.0 asLongFloat printString.
1e10 asLongFloat printString.
1.2e3 asLongFloat printString.
1.2e30 asLongFloat printString.
(1.0 uncheckedDivide:0) asLongFloat printString.
(0.0 uncheckedDivide:0) asLongFloat printString.
self pi printString.
DecimalPointCharacterForPrinting := $,.
1.234 asLongFloat printString.
1.0 asLongFloat printString.
1e10 asLongFloat printString.
1.2e3 asLongFloat printString.
1.2e30 asLongFloat printString.
(1.0 uncheckedDivide:0) asLongFloat printString.
(0.0 uncheckedDivide:0) asLongFloat printString.
DecimalPointCharacterForPrinting := $.
|
-
printStringWithFormat: format
-
return a printed representation of the receiver;
fmt must be of the form: .nn, where nn is the number of digits.
To print 6 valid digits, use printStringWithFormat:'.6'
For Floats, the default used in printString, is 15 (because its a double);
for ShortFloats, it is 6 (because it is a float),
for Extended (LongFloats) it is 19
-
printfPrintString: formatString
-
non-standard: return a printed representation of the receiver
as specified by formatString, which is defined by printf.
If you use this, be aware, that specifying long doubles differs on
systems; on Linux/gnuc machines you have to give something like %LF/%LG.
Also, the resulting string may not be longer than 1000 bytes -
since that's the (static) size of the buffer.
This method is NONSTANDARD and may be removed without notice.
WARNING: this goes directly to the C-printf function and is therefore inherently unsafe.
Please use the printf: method, which is safe as it is completely implemented in Smalltalk.
Usage example(s):
1.234 asLongFloat printfPrintString:'%%LG -> %LG' '%LG -> 1.234'
1.234 asLongFloat printfPrintString:'%%LF -> %LF' '%LF -> 1.234000'
1.234 asLongFloat printfPrintString:'%%5.3LF -> %5.3LF' '%5.3LF -> 1.234'
Float pi asLongFloat printfPrintString:'%%LG -> %LG'
Float pi asLongFloat printfPrintString:'%%LF -> %LF'
Float pi asLongFloat printfPrintString:'%%LE -> %LE'
Float pi asLongFloat printfPrintString:'%%7.15LG -> %7.15LG'
Float pi asLongFloat printfPrintString:'%%7.15LF -> %7.15LF'
Float pi asLongFloat printfPrintString:'%%f -> %f' '%f -> 3.141593'
Float pi asLongFloat printfPrintString:'%%lf -> %lf' '%lf -> 3.141593'
Float pi asLongFloat printfPrintString:'%%lF -> %lF' '%lF -> 3.141593'
Float pi asLongFloat printfPrintString:'%%Lf -> %Lf' '%Lf -> 3.141593'
Float pi asLongFloat printfPrintString:'%%LF -> %LF' '%LF -> 3.141593'
LongFloat NaN printfPrintString:'%%f -> %f' '%f -> nan'
LongFloat NaN printfPrintString:'%%lf -> %lf' '%lf -> nan'
LongFloat NaN printfPrintString:'%%lF -> %lF' '%lF -> NAN'
LongFloat NaN printfPrintString:'%%Lf -> %Lf' '%Lf -> nan'
LongFloat NaN printfPrintString:'%%LF -> %LF' '%LF -> NAN'
LongFloat infinity printfPrintString:'%%f -> %f' '%f -> inf'
LongFloat infinity printfPrintString:'%%lf -> %lf' '%lf -> inf'
LongFloat infinity printfPrintString:'%%lF -> %lF' '%lF -> INF'
LongFloat infinity printfPrintString:'%%Lf -> %Lf' '%Lf -> inf'
LongFloat infinity printfPrintString:'%%LF -> %LF' '%LF -> INF'
|
-
storeOn: aStream
-
append a printed representation of the receiver to
the argument, aStream.
I use #storeString instead of #storeOn: as basic store mechanism.
-
storeString
-
return a printed representation of the receiver;
all valid digits are printed.
LimitedPrecisonReal and its subclasses use #storeString instead of
#storeOn: as basic print mechanism.
Usage example(s):
1.0 asLongFloat storeString
1.234 asLongFloat storeString
1e10 asLongFloat storeString
1.2e3 asLongFloat storeString
1.2e30 asLongFloat storeString
LongFloat pi asLongFloat storeString
(1.0 uncheckedDivide:0) asLongFloat storeString
(0.0 uncheckedDivide:0) asLongFloat storeString
notice that the storeString is NOT affected by DecimalPointCharacterForPrinting:
DecimalPointCharacterForPrinting := $,.
1.234 asLongFloat storeString.
1.0 asLongFloat storeString.
1e10 asLongFloat storeString.
1.2e3 asLongFloat storeString.
1.2e30 asLongFloat storeString.
(1.0 uncheckedDivide:0) asLongFloat storeString.
(0.0 uncheckedDivide:0) asLongFloat storeString.
DecimalPointCharacterForPrinting := $.
|
private accessing
-
basicAt: index
-
return an internal byte of the float.
The value returned here depends on byte order, float representation etc.
Therefore, this method should be used strictly private.
Notice:
the need to redefine this method here is due to the
inability of many machines to store floats in non-double aligned memory.
Therefore, on some machines, the first <nPad> bytes of a float are left unused,
and the actual float is stored at index <nPad>+1 ...
To hide this at one place, this method knows about that, and returns
values as if this filler wasnt present.
-
basicAt: index put: value
-
set an internal byte of the float.
The value to be stored here depends on byte order, float representation etc.
Therefore, this method should be used strictly private.
Notice:
the need to redefine this method here is due to the
inability of many machines to store floats in non-double aligned memory.
Therefore, on some machines, the first <nPad> bytes of a float are left unused,
and the actual float is stored at index <nPad>+1 .. .
To hide this at one place, this method knows about that, and returns
values as if this filler wasnt present.
-
basicSize
-
return the size in bytes of the float.
Notice:
the need to redefine this method here is due to the
inability of many machines to store floats in non-double aligned memory.
Therefore, on some machines, the first <nPad> bytes of a float are left unused,
and the actual float is stored at index <nPad>+1 ...
To hide this at one place, this method knows about that, and returns
values as if this filler wasnt present.
-
byteAt: index
-
(comment from inherited method)
return the byte at index.
This is only allowed for non-pointer indexed objects
(i.e. byteArrays, wordArrays, floatArrays etc.).
The receiver's indexed instvars are treated as an uninterpreted
collection of bytes.
Only useful with binary storage.
-
byteAt: index put: newByte
-
(comment from inherited method)
set the byte at index.
This is only allowed for non-pointer indexed objects
(i.e. byteArrays, wordArrays, floatArrays etc.).
The receiver's indexed instvars are treated as an uninterpreted
collection of bytes.
Only useful with binary storage.
-
byteSize
-
the number of bytes in a longFloat.
Redefined to care for MINGW, which stores 10 bytes in 16 bytes
Usage example(s):
10 asLongFloat byteSize
10 asLongFloat asIEEEFloat
10 asLongFloat asQuadFloat
|
-
signBit
-
return the sign bit (1 for negative).
notice that floats can represent a negative zero,
and signBit handles that,
whereas sign would return 0 for both positive and negative zeros
Usage example(s):
1.0 asLongFloat signBit -> 0
-1.0 asLongFloat signBit -> 1
LongFloat zero signBit -> 0
LongFloat negativeZero signBit -> 1
|
queries
-
hasIEEEFormat
-
(comment from inherited method)
HalfFloat isIEEEFormat true
ShortFloat isIEEEFormat true
Float isIEEEFormat true
LongFloat isIEEEFormat true
QuadFloat isIEEEFormat true
OctaFloat isIEEEFormat true
QDouble isIEEEFormat false
LargeFloat isIEEEFormat false
-
nextFloat: countULPs
-
answer the next float count places (ulps) after (or before if count is negative) myself.
One ulp is the distance to the next/previous representable float,
and this returns the float which is countUlps away from me.
Notice that ulps depend on the receiver: an ulp away from 1e100 has a different
value than 1 ulp away from 1e-100.
Thus, ulps are perfect for 'almost equal' comparisons.
Usage example(s):
(1.0 nextFloat:2) storeString '1.0000000000000004'
(1.0 asShortFloat nextFloat:2) storeString '1.0000002'
(1.0 asLongFloat nextFloat:2) storeString '1.0000000000000000002'
(1.0 nextFloat:1) storeString '1.0000000000000002'
(1.0 asShortFloat nextFloat:1) storeString '1.0000001'
(1.0 asLongFloat nextFloat:1) storeString '1.0000000000000000001'
(1.0 nextFloat:-1) storeString '0.99999999999999989'
(1.0 asShortFloat nextFloat:-1) storeString '0.99999994'
(1.0 asLongFloat nextFloat:-1) storeString '0.99999999999999999989'
(0.0 nextFloat:-1) storeString '-4.9406564584124654E-324'
((0.0 nextFloat:-1)nextFloat:1) storeString '-9.8813129168249309E-324'
(0.0 asShortFloat nextFloat:-1) storeString '1.4012985e-45'
(0.0 asLongFloat nextFloat:-1) storeString '6.7242062862241870122E-4932'
(0.0 asLongFloat nextFloat:1) storeString '6.7242062862241870122E-4932'
(67329.234) storeString '67329.233999999997'
(67329.234 nextFloat:1) storeString '67329.234000000011'
(67329.234 asShortFloat) storeString '67329.234'
(67329.234 asShortFloat nextFloat:1) storeString '67329.242'
(67329.234 asLongFloat) storeString '67329.23399999999674'
(67329.234 asLongFloat nextFloat:1) storeString '67329.233999999996747'
ShortFloat NaN nextFloat:1 nan
ShortFloat NaN nextFloat:-1 nan
ShortFloat NaN nextFloat:100000 nan
ShortFloat infinity nextFloat:1 inf
ShortFloat infinity nextFloat:-1 inf
ShortFloat infinity nextFloat:100000 inf
Float NaN nextFloat:1 nan
Float NaN nextFloat:-1 nan
Float NaN nextFloat:100000 nan
Float infinity nextFloat:1 inf
Float infinity nextFloat:-1 inf
Float infinity nextFloat:100000 inf
LongFloat NaN nextFloat:1 NAN
LongFloat NaN nextFloat:-1 NAN
LongFloat NaN nextFloat:100000 NAN
LongFloat infinity nextFloat:1 INF
LongFloat infinity nextFloat:-1 INF
LongFloat infinity nextFloat:100000 INF
(10.0 asLongFloat nextFloat) - 10.0 -> 8.673617379884035472e-19
(-10.0 asLongFloat nextFloat) - -10.0 -> 8.673617379884035472e-19
(10.0 asLongFloat previousFloat) - 10.0 -> -8.673617379884035472e-19
(-10.0 asLongFloat previousFloat) - -10.0 -> -8.673617379884035472e-19
|
special access
-
exponent
-
extract a normalized float's (unbiased) 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 float's value is mantissa * 2^exp
Usage example(s):
4.0q exponent
2.0q exponent
1.0q exponent
0.5q exponent
0.25q exponent
0.00000011111q exponent
1.0q1000 exponent
LongFloat NaN exponent
|
-
mantissa
-
extract a normalized float's mantissa (as LongFloat).
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 float's value is mantissa * 2^exp
Usage example(s):
0.0 asLongFloat exponent
0.0 asLongFloat mantissa
1.0 asLongFloat exponent -> 1
1.0 asLongFloat mantissa -> 0.5
3.0 asLongFloat exponent -> 2
3.0 asLongFloat mantissa -> 0.75
1.0q exponent
1.0q mantissa
0.5q exponent
0.5q mantissa
16q exponent
16q mantissa
10q exponent -> 4
10q mantissa -> 0.625
-9q exponent -> 4
-9q mantissa -> -0.5625
0.25q exponent
0.25q mantissa
0.00000011111q exponent
0.00000011111q mantissa
self assert:(1.0 asLongFloat mantissa * (2 raisedTo:1.0 asLongFloat exponent)) = 1.0 asLongFloat.
self assert:(100.0 asLongFloat mantissa * (2 raisedTo:100.0 asLongFloat exponent)) = 100.0 asLongFloat.
self assert:(10e15 asLongFloat mantissa * (2 raisedTo:10e15 asLongFloat exponent)) = 10e15 asLongFloat.
self assert:(10e-15 asLongFloat mantissa * (2 raisedTo:10e-15 asLongFloat exponent)) = 10e-15 asLongFloat.
LongFloat NaN mantissa -> error
LongFloat NaN exponent -> error
|
testing
-
isFinite
-
return true, if the receiver is a finite float (not NaN and not +/-INF)
Usage example(s):
1.0 asLongFloat isFinite -> true
LongFloat infinity isFinite -> false
LongFloat negativeInfinity isFinite -> false
LongFloat NaN isFinite -> false
(0.0 asLongFloat uncheckedDivide: 0.0) isFinite -> false
(1.0 asLongFloat uncheckedDivide: 0.0) isFinite -> false
(-1.0 asLongFloat uncheckedDivide: 0.0) isFinite -> false
|
-
isFloat128
-
Answer whether the receiver is a quadruple precision float.
-
isFloat80
-
Answer whether the receiver is a 80bit extended precision float.
-
isInfinite
-
return true, if the receiver is an infinite float (+Inf or -Inf).
These are not created by ST/X float operations (they raise an exception);
however, inline C-code could produce them.
Usage example(s):
1.0 asLongFloat isFinite -> true
1.0 asLongFloat isInfinite -> false
(0.0 asLongFloat uncheckedDivide: 0.0) isFinite -> false
(0.0 asLongFloat uncheckedDivide: 0.0) isInfinite -> false
(0.0 asLongFloat uncheckedDivide: 0.0) isNaN -> true
(1.0 asLongFloat uncheckedDivide: 0.0) isFinite -> false
(1.0 asLongFloat uncheckedDivide: 0.0) isInfinite -> true
(1.0 asLongFloat uncheckedDivide: 0.0) isNaN -> false
(-1.0 asLongFloat uncheckedDivide: 0.0) isFinite -> false
(-1.0 asLongFloat uncheckedDivide: 0.0) isInfinite -> true
(-1.0 asLongFloat uncheckedDivide: 0.0) isNaN -> false
|
-
isLongFloat
-
return true, if the receiver is some kind of long floating point number (iee extended precision)
-
isNaN
-
return true, if the receiver is an invalid float (NaN - not a number).
These are usually not created by ST/X float operations (they raise an exception);
however, inline C-code or proceeded exceptions or reading from a stream
could produce them.
Usage example(s):
1.0 asLongFloat isNaN
(0.0 asLongFloat uncheckedDivide: 0.0) isNaN
|
-
isNegativeZero
-
many systems have two float.Pnt zeros
Usage example(s):
0.0 asLongFloat isNegativeZero
-0.0 asLongFloat isNegativeZero
|
-
negative
-
return true if the receiver is less than zero.
-0.0 is positive for now.
Usage example(s):
0.0 asLongFloat negative
-0.0 asLongFloat negative
1.0 asLongFloat negative
-1.0 asLongFloat negative
(1.0 uncheckedDivide: 0.0) asLongFloat negative
(-1.0 uncheckedDivide: 0.0) asLongFloat negative
|
-
numberOfBits
-
return the size (in bits) of the real;
typically, 80 or 96 is returned here,
but who knows ...
Usage example(s):
LongFloat basicNew numberOfBits
1.2 asLongFloat numberOfBits
1.2 asShortFloat numberOfBits
1.2 numberOfBits
|
-
positive
-
return true if the receiver is greater or equal to zero (not negative)
0.0 and -0.0 are positive for now.
Usage example(s):
0.0 asLongFloat positive
-0.0 asLongFloat positive
1.0 asLongFloat positive
-1.0 asLongFloat positive
(1.0 uncheckedDivide: 0.0) asLongFloat positive
(-1.0 uncheckedDivide: 0.0) asLongFloat positive
|
-
strictlyPositive
-
return true if the receiver is greater than zero
trigonometric
-
arcCos
-
return the arccosine of the receiver (as radians).
Raises an exception, if the receiver is not in -1..1
Usage example(s):
-10 asLongFloat arcCos
1 asLongFloat arcCos
0.5 asLongFloat arcCos
|
-
arcSin
-
return the arcsine of the receiver (as radians).
Raises an exception, if the receiver is not in -1..1
Usage example(s):
-10 asLongFloat arcSin
1 asLongFloat arcSin
0.5 asLongFloat arcSin
|
-
arcTan
-
return the arctangent of the receiver (as radians)
-
arcTan2: x
-
return the arctangent of the receiver (as radians)
Usage example(s):
0q arcTan2:0q -> error
1q arcTan2:0q -> 1.5707963267949 (pi/2)
-1q arcTan2:0q -> -1.5707963267949 (-pi/2)
0q arcTan2:-1q -> 3.14159265358979 (pi)
0q arcTan2:1q -> 0.0
1q arcTan2:1q -> 0.785398163397448 (pi/4)
-1q arcTan2:-1q -> -2.35619449019234 -(3/4 pi)
1q arcTan2:-1q -> 2.35619449019234 (3/4 pi)
-1 arcTan2:1 -> -0.785398163397448 -(pi/4)
2 arcTan:1 -> 1.10714871779409
1 arcTan:2 -> 0.463647609000806
|
-
cos
-
return the cosine of the receiver (interpreted as radians)
-
sin
-
return the sine of the receiver (interpreted as radians)
-
tan
-
return the tangens of the receiver (interpreted as radians)
trigonometric - hyperbolic
-
arCosh
-
return the hyperbolic area cosine of the receiver.
Usage example(s):
1e50 asLongFloat arCosh
1e20 asLongFloat arCosh
-10 asLongFloat arCosh
1 asLongFloat arCosh
0.5 asLongFloat arCosh
|
-
arSinh
-
return the hyperbolic area sine of the receiver.
Usage example(s):
-10 asLongFloat arSinh
1 asLongFloat arSinh
0.5 asLongFloat arSinh
|
-
arTanh
-
return the hyperbolic area tangent of the receiver.
-
cosh
-
return the hyperbolic cosine of the receiver (interpreted as radians)
-
sinh
-
return the hyperbolic sine of the receiver
-
tanh
-
return the hyperbolic tangens of the receiver
truncation & rounding
-
ceiling
-
return the smallest integer which is greater or equal to the receiver.
Usage example(s):
0.5q ceiling
-0.5q ceiling
|
-
ceilingAsFloat
-
return the smallest integer-valued float greater or equal to the receiver.
This is much like #ceiling, but avoids a (possibly expensive) conversion
of the result to an integer.
It may be useful, if the result is to be further used in another float-operation.
Usage example(s):
0.5q ceilingAsFloat
-0.5q ceilingAsFloat
-1.5q ceilingAsFloat
|
-
floor
-
return the integer nearest the receiver towards negative infinity.
Usage example(s):
-
floorAsFloat
-
return the float which represents the next lower
integer nearest the receiver towards negative infinity.
Much like floor, but returns a float result - useful if the result
will be used in another float operation, to avoid costy int-conversion.
Usage example(s):
0.5q floorAsFloat
-0.5q floorAsFloat
-1.5q floorAsFloat
|
-
fractionPart
-
extract the after-decimal fraction part.
such that:
(self truncated + self fractionPart) = self
Usage example(s):
1.6q fractionPart + 1.6q truncated
-1.6q fractionPart + -1.6q truncated
1.0q fractionPart
2.0q fractionPart
3.0 asLongFloat fractionPart
4.0 asLongFloat fractionPart
0.5 asLongFloat fractionPart
0.25 asLongFloat fractionPart
3.14159 asLongFloat fractionPart
12345673.14159 asLongFloat fractionPart
123456731231231231.14159 asLongFloat fractionPart
3.14159 asLongFloat fractionPart + 3.14159 asLongFloat truncated
12345673.14159 asLongFloat fractionPart + 12345673.14159 asLongFloat truncated
123456731231231231.14159 asLongFloat fractionPart + 123456731231231231.14159 asLongFloat truncated
|
-
integerAndFractionParts
-
return the integer and the fraction part of the receiver as a pair
of floats (i.e. the result of the modf function)
Adding the parts gives the original value
Usage example(s):
0.5 asLongFloat integerAndFractionParts
-0.5 asLongFloat integerAndFractionParts
12345.6789 asLongFloat integerAndFractionParts
-12345.6789 asLongFloat integerAndFractionParts
|
-
rounded
-
return the receiver rounded to the nearest integer
Usage example(s):
0.4q rounded
0.5q rounded
0.6qqrounded
-0.4q rounded
-0.5q rounded
-0.6q rounded
|
-
roundedAsFloat
-
return the receiver rounded to the nearest integer as a float.
This is much like #rounded, but avoids a (possibly expensive) conversion
of the result to an integer.
It may be useful, if the result is to be further used in another float-operation.
-
truncated
-
return the receiver truncated towards zero as an integer
Usage example(s):
0.5q truncated
-0.5q truncated
0.5q truncatedAsFloat
-0.5q truncatedAsFloat
|
-
truncatedAsFloat
-
return the receiver truncated towards zero as a long float.
This is much like #truncated, but avoids a (possibly expensive) conversion
of the result to an integer.
It may be useful, if the result is to be further used in another
float-operation.
Usage example(s):
0.5q truncated
-0.5q truncated
0.5q truncatedAsFloat
-0.5q truncatedAsFloat
|
|