eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'LongFloat':

Home

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

Class: LongFloat


Inheritance:

   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

Description:


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

copyright

COPYRIGHT (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.

Class protocol:

accessing
o  defaultPrintFormat
'.19' by default, I will print up to 19 digits

o  defaultPrintFormat: aFormatString
the formatString must be of the form '.n'.

class initialization
o  initialize
print up to 19 valid digits

Usage example(s):

     Epsilon := nil.
     self initialize.
     Epsilon -> 1.08420e-19

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 longFloat which represents not-a-Number (i.e. an invalid number)

Usage example(s):

whereas all others return a positive NaN

Usage example(s):

     LongFloat NaN

o  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

o  halfPi
return the constant pi/2 as LongFloat

Usage example(s):

     self halfPi

o  halfPiNegative
return the constant -pi/2 as LongFloat

Usage example(s):

     self halfPiNegative

o  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):

     LongFloat infinity

o  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

o  phi
return the constant phi as LongFloat

Usage example(s):

phiDigits has enough digits for 128bit IEEE quads

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

o  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

o  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

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

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

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

o  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

o  fromBytes: bytes exponentSize: exponentSize

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

Usage example(s):

     LongFloat fromFloat:123.0
     123.0 asLongFloat
     123 asLongFloat

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

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

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

Usage example(s):

     LongFloat fromInteger:123
     LongFloat fromInteger:(100 factorial)
     (100 factorial) asLongFloat

o  fromShortFloat: aFloat
return a new longFloat, given a shortFloat value

Usage example(s):

     LongFloat fromShortFloat:(123.0 asShortFloat)
     LongFloat fromShortFloat:122

queries
o  defaultPrintPrecision
the default number of digits when printing

Usage example(s):

     LongFloat defaultPrintPrecision
     ShortFloat defaultPrintPrecision
     Float defaultPrintPrecision

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

o  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

o  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

o  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

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

o  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

o  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

o  fminDenormalized
The smallest non-zero value allowed by denormalized instances of this class.

Usage example(s):

^ super fminDenormalized

Usage example(s):

     LongFloat fmin              -> 3.362103143112093506E-4932
     LongFloat fminDenormalized  -> 0.000000000000000004e-4933

o  isBuiltInClass
return true if this class is known by the run-time-system.
Here, true is returned for myself, false for subclasses.

o  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

o  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

o  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

o  radix
answer the radix of a LongFloat'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  abs
return the absolute value of the receiver
reimplemented here for speed

Usage example(s):

     3.0 asLongFloat abs
     -3.0 asLongFloat abs

o  negated
return myself negated

Usage example(s):

     0 negated
     0.0 negated
     0.0 asLongFloat negated

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

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

o  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

o  asInteger
return an integer with same value - might truncate

Usage example(s):

     12345.0 asLongFloat asInteger
     1e15 asLongFloat asInteger

o  asLongFloat
return a LongFloat with same value as the receiver - that's me

o  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 

o  asQuadFloat
( an extension from the stx:libbasic2 package )
return a QuadFloat with same value as the receiver

o  asShortFloat
return a ShortFloat with same value as the receiver.
Does NOT raise any error if the receiver exceeds the short float range.

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

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

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

o  <= aNumber
return true, if the argument is greater or equal

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

o  > aNumber
return true, if the argument is less

o  >= aNumber
return true, if the argument is less or equal

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 asLongFloat hash
     1 hash
     1.0 hash
     1.0 asLongFloat hash

o  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

o  ~= aNumber
return true, if the arguments value are not equal.

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  productFromInteger: anInteger
sent when an integer does not know how to multiply the receiver, self

o  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

o  raisedFromFloat: aFloat
aFloat does not know how to be raised to the receiver

o  sumFromInteger: anInteger
sent when an integer does not know how to add the receiver, self

mathematical functions
o  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)

o  erf
return the error function of myself.

Usage example(s):

     4 erf
     -4 erf

o  exp
return e raised to the power of the receiver

o  gamma
return the gamma function value of myself.

Usage example(s):

     172 gamma   => inf
     172q gamma  => 1.241018070217667861e+309

o  ln
return the natural logarithm of myself.
Raises an exception, if the receiver is less or equal to zero.

o  log10
return the base-10 logarithm of the receiver.
Raises an exception, if the receiver is less or equal to zero.

o  raisedTo: aNumber
return self raised to the power of aNumber

o  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
o  printOn: aStream
append a printed representation of the receiver to
the argument, aStream.

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

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 := $.

o  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

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

o  storeOn: aStream
append a printed representation of the receiver to
the argument, aStream.

I use #storeString instead of #storeOn: as basic store mechanism.

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

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

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

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

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

o  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

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

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

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

o  isFloat128
Answer whether the receiver is a quadruple precision float.

o  isFloat80
Answer whether the receiver is a 80bit extended precision float.

o  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

o  isLongFloat
return true, if the receiver is some kind of long floating point number (iee extended precision)

o  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

o  isNegativeZero
many systems have two float.Pnt zeros

Usage example(s):

     0.0 asLongFloat isNegativeZero
     -0.0 asLongFloat isNegativeZero

o  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

o  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

o  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

o  strictlyPositive
return true if the receiver is greater than zero

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

o  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

o  arcTan
return the arctangent of the receiver (as radians)

o  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

o  cos
return the cosine of the receiver (interpreted as radians)

o  sin
return the sine of the receiver (interpreted as radians)

o  tan
return the tangens of the receiver (interpreted as radians)

trigonometric - hyperbolic
o  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

o  arSinh
return the hyperbolic area sine of the receiver.

Usage example(s):

     -10 asLongFloat arSinh
     1 asLongFloat arSinh
     0.5 asLongFloat arSinh

o  arTanh
return the hyperbolic area tangent of the receiver.

o  cosh
return the hyperbolic cosine of the receiver (interpreted as radians)

o  sinh
return the hyperbolic sine of the receiver

o  tanh
return the hyperbolic tangens of the receiver

truncation & rounding
o  ceiling
return the smallest integer which is greater or equal to the receiver.

Usage example(s):

     0.5q ceiling
     -0.5q ceiling

o  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

o  floor
return the integer nearest the receiver towards negative infinity.

Usage example(s):

     0.5q floor
     -0.5q floor

o  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

o  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

o  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

o  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

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

o  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

o  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



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 27 Jul 2024 04:02:28 GMT