eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'AbstractIEEEFloat':

Home

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

Class: AbstractIEEEFloat


Inheritance:

   Object
   |
   +--Magnitude
      |
      +--ArithmeticValue
         |
         +--Number
            |
            +--LimitedPrecisionReal
               |
               +--AbstractIEEEFloat
                  |
                  +--IEEEFloat
                  |
                  +--OctaFloat
                  |
                  +--QuadFloat

Package:
stx:libbasic2
Category:
Magnitude-Numbers
Version:
rev: 1.67 date: 2024/04/24 09:11:48
user: stefan
file: AbstractIEEEFloat.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


common abstract superclass for emulated IEEE floats.


Related information:

    [ttps]

Class protocol:

constants
o  NaN
return a float here, assuming that all of my instances can deal with that

o  infinity
return a float here, assuming that all of my instances can deal with that

o  ln10
return a float here, assuming that all of my instances can deal with that

o  ln2
return a float here, assuming that all of my instances can deal with that

o  negativeInfinity
return a float here, assuming that all of my instances can deal with that

o  unity
return the neutral element for multiplication (1)

o  zero
return a float here, assuming that all of my instances can deal with that

instance creation
o  fromBytes: bytes
bytes are assumed to be given in LSB first byte order

Usage example(s):

     IEEEFloat fromBytes:#[0 0 0 0 0 0 0 0] exponentSize:11 
     IEEEFloat fromBytes:#[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] exponentSize:15 

     QuadFloat fromBytes:#[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

o  fromBytes: bytes MSB: bytesAreMSB
IEEEFloat fromBytes:#[0 0 0 0 0 0 0 0] exponentSize:11
IEEEFloat fromBytes:#[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] exponentSize:15

QuadFloat fromBytes:#[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
QuadFloat fromBytes:#[64 0 201 15 218 162 33 104 194 52 196 198 98 139 128 220] MSB:true

o  fromBytes: bytes exponentSize: exponentSize
bytes are assumed to be given in LSB first byte order

Usage example(s):

     self fromBytes:#[0 0 0 0 0 0 0 0] exponentSize:11 
     self fromBytes:#[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] exponentSize:15 

o  fromBytes: bytes exponentSize: exponentSize MSB: bytesAreMSB
self fromBytes:#[0 0 0 0 0 0 0 0] exponentSize:11
self fromBytes:#[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] exponentSize:15

o  fromFloat: aFloat
creates an instance of me with the same size as the argument
(i.e. a 1:1 copy, if all goes well;
which is not true for x86 longFloats,
which has a hidden bit in the copy, but has not in the original)

Usage example(s):

     self fromFloat:1.0
     self fromFloat:2.0
     self fromFloat:1.0 asShortFloat
     self fromFloat:2.0 asShortFloat
     self fromFloat:1.0 asLongFloat
     self fromFloat:2.0 asLongFloat
     self fromFloat:3.0 asLongFloat
     self fromFloat:101.0 asLongFloat
     self fromFloat:0.0 asLongFloat
     self fromFloat:0.5 asLongFloat

o  fromFloat: aFloat byteSize: byteSizeOrNil
creates an instance of me with byteSizeOrNil
or the same size as the argument (if byteSizeOrNil is nil)
(i.e. a 1:1 copy, of the original float if all goes well;
which is not true for x86 longFloats,
which have a hidden bit in the copy, but not in the original)

Usage example(s):

^ self fromFloat:aFloat byteSize:nB numBitsInExponent:nBitsInExponent

o  fromFloat: aFloat byteSize: byteSizeOrNil numBitsInExponent: numBitsInExponentOrNil
creates an instance of me with byteSizeOrNil
or the same size as the argument (if byteSizeOrNil is nil)
(i.e. a 1:1 copy, of the original float
which is not true for x86 longFloats, which have a hidden bit in the copy, but not in the original)

Usage example(s):

     self fromFloat:1.0     
     self fromFloat:2.0     
     self fromFloat:1.0 asShortFloat   
     self fromFloat:2.0 asShortFloat   
     self fromFloat:0.0 asLongFloat    
     self fromFloat:1.0 asLongFloat    
     self fromFloat:2.0 asLongFloat  
     self fromFloat:3.0 asLongFloat  

     self fromFloat:101.0 asLongFloat
     self fromFloat:0.0 asLongFloat
     self fromFloat:0.5 asLongFloat

     1.0 asIEEEFloat:16          
     0.5 asIEEEFloat:16          
     Float NaN asIEEEFloat:16    
     Float infinity asIEEEFloat:16   
     Float negativeInfinity asIEEEFloat:16  

     1.0 asIEEEFloat:128 
     0.5 asIEEEFloat:128 
     Float NaN asIEEEFloat:128 

     Float NaN asIEEEFloat   
     Float infinity asIEEEFloat   
     Float negativeInfinity asIEEEFloat   

o  fromInteger: anInteger byteSize: byteSizeOrNil
convert to one of 32, 64, 128, 256 or even 512 bit IEEEFloat.
If byteSizeOrNil is non-nil, that size float is generated,
and an error is raised, if the number is too large.
Otherwise, if byteSizeOrNil is nil,
a float with the required size is returned.
The error is proceedable, to return infinity

Usage example(s):

     self fromInteger:1
     self fromInteger:1 byteSize:4
     self fromInteger:1 byteSize:16
     self fromInteger:-1
     self fromInteger:2
     self fromInteger:1024 * 1024 * 1024 * 1024 * 1024 * 1024
     self fromInteger:1e20 asInteger
     self fromInteger:1e100 asInteger
     self fromInteger:2r1010101010101010101010101010101
     self fromInteger:2r1010101010101010101010101010101010101010101010101010101010101010
     self fromInteger:1e-100 asInteger
     1 asIEEEFloat

o  fromInteger: anInteger byteSize: byteSizeOrNil numBitsInExponent: numBitsInExponentOrNil
convert to one of 32, 64, 128, 256 or even 512 bit IEEEFloat.
If byteSizeOrNil is non-nil, that size float is generated,
and an error is raised, if the number is too large.
Otherwise, if byteSizeOrNil is nil,
a float with the required size is returned.
The error is proceedable, to return infinity

Usage example(s):

     self fromInteger:1
     self fromInteger:1 byteSize:4
     self fromInteger:1 byteSize:16
     self fromInteger:-1
     self fromInteger:2
     self fromInteger:1024 * 1024 * 1024 * 1024 * 1024 * 1024
     self fromInteger:1e20 asInteger
     self fromInteger:1e100 asInteger
     self fromInteger:2r1010101010101010101010101010101
     self fromInteger:2r1010101010101010101010101010101010101010101010101010101010101010
     self fromInteger:1e-100 asInteger
     1 asIEEEFloat

o  new: nBytes exponentSize: nExponentBits
QuadFloat: 128bit

Usage example(s):

     self new:4  exponentSize:24
     self new:8  exponentSize:24
     self new:16 exponentSize:15
     self new:16 exponentSize:20
     self new:32 exponentSize:19
     self new:32 exponentSize:22
     self new:64
     OctaFloat new

o  size: numBits exponentSize: exponentSize
self size:32 exponentSize:11
self size:128 exponentSize:15
self size:256 exponentSize:19
self size:16 exponentSize:5
self size:(1.0 basicSize * 8) exponentSize:(1.0 numBitsInExponent)

o  size: numBits exponentSize: exponentSize fraction: normalizedFraction biasedExponent: biasedExponent signBit: signBit
self size:256 exponentSize:19 fromInteger:1
self size:256 exponentSize:19 fromInteger:2
self size:64 exponentSize:11 fraction:0 exponent:(0 + Float eBias) signBit:0
self size:64 exponentSize:11 fraction:0 exponent:0 signBit:0

o  size: numBits exponentSize: exponentSize fraction: normalizedFraction exponent: biasedExponent signBit: signBit
self size:256 exponentSize:19 fromInteger:1
self size:256 exponentSize:19 fromInteger:2
self size:64 exponentSize:11 fraction:0 exponent:(0 + Float eBias) signBit:0
self size:64 exponentSize:11 fraction:0 exponent:0 signBit:0

o  size: numBits exponentSize: exponentSize fromFloat: aFloat
self size:256 exponentSize:19 fromFloat:1.0
self size:256 exponentSize:19 fromFloat:2.0
self size:128 exponentSize:15 fromFloat:2.0

queries
o  defaultExponentSizeForByteSize: nBytes
self defaultExponentSizeForByteSize:2 5
self defaultExponentSizeForByteSize:4 8
self defaultExponentSizeForByteSize:5 8
self defaultExponentSizeForByteSize:8 11
self defaultExponentSizeForByteSize:10 15
self defaultExponentSizeForByteSize:16 15
self defaultExponentSizeForByteSize:32 19
self defaultExponentSizeForByteSize:64 32

o  fmax
the largest finite value which can be represented by instances with the same
layout (i.e. same number of exponent bits) as an instance with my layout.
Notice: although defined here in this abstract class,
this can only be answered for a concrete subclass with a fixed exponentSize
(i.e. QuadFloats and OctaFloats). For arbitrary IEEEFloats, this must be sent to an instance

Usage example(s):

     ShortFloat fmax -> 3.402823e+38
     Float fmax      -> 1.79769313486232e+308
     QuadFloat fmax  -> 1.18973149e4932 
     OctaFloat fmax  -> 1.6113257174e78913 

     ShortFloat fmin -> 1.175494e-38
     Float fmin      -> 2.2250738585072e-308
     QuadFloat fmin  -> 3.36210314e-4932 
     OctaFloat fmin  -> 2.4824279515e-78913 

o  fmaxDenormalized
the largest denormalized value which can be represented by instances with the same
layout (i.e. same number of exponent bits) as an instance with my layout

Usage example(s):

     QuadFloat fmaxDenormalized  -> 0.16810516e-4931
     OctaFloat fmaxDenormalized  -> 1.2412139757e-78913

o  fmin
the smallest normalized non-zero value which can be represented by instances with the same
layout (i.e. same number of exponent bits) as an instance with my layout.
Notice: although defined here in this abstract class,
this can only be answered for a concrete subclass with a fixed exponentSize
(i.e. QuadFloats and OctaFloats). For arbitrary IEEEFloats, this must be sent to an instance

Usage example(s):

     ShortFloat fmin -> 1.175494e-38
     Float fmin      -> 2.2250738585072e-308
     QuadFloat fmin  -> 3.36210314e-4932 
     OctaFloat fmin  -> 2.4824279515e-78913 

     ShortFloat fmax -> 3.402823e+38
     Float fmax      -> 1.79769313486232e+308
     QuadFloat fmax  -> 1.18973149e4932 
     OctaFloat fmax  -> 1.6113257174e78913 

o  fminDenormalized
the smallest non-zero value which can be represented by denormalized instances with the same
layout (i.e. same number of exponent bits) as an instance with my layout

Usage example(s):

     QuadFloat fminDenormalized -> 0.1556536e-4965
     OctaFloat fminDenormalized -> 1.1240035432e-78984

o  isAbstract
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.


Instance protocol:

accessing
o  exponentBits
return the bits of my exponent.
These might be biased.
My bytes are stored LSB first;
thus we have to fetch the high exponent bytes.

Usage example(s):

     1.0 asShortFloat asIEEEFloat
     (1 to:4) conform:[:i | (1.0 asShortFloat basicAt:i) = (1.0 asShortFloat asIEEEFloat basicAt:i)]
     1.0 asShortFloat exponentBits 
     1.0 asShortFloat asIEEEFloat exponentBits  -> 127
     -1.0 exponentBits                -> 1023
     -1.0 asQuadFloat exponentBits    -> 16383
     -1.0 asOctaFloat exponentBits    -> 262143
     -1.0 asShortFloat exponentBits   -> 127
     -1.0 asShortFloat asIEEEFloat exponentBits -> 127  
     -1.0 asIEEEFloat exponentBits    -> 1023  

     (self size:32 exponentSize:8) inspect.
     (self size:64 exponentSize:11) inspect.
     (self size:128 exponentSize:16) inspect.
     (self size:128 exponentSize:19) inspect.
     (self size:256 exponentSize:16) inspect.

o  exponentSize

** This method must be redefined in concrete classes (subclassResponsibility) **

o  mantissaBits
return the bits of my mantissa (excl. any hidden bit).
I.e. this returns the nosrmalized mantissaBits as an integer.
My bytes are stored in the native byte order.

Usage example(s):

    (self size:32 exponentSize:8) inspect.
    (self size:32 exponentSize:8) mantissaBits.
    (self fromFloat:1.0) mantissaBits. 
    (self fromFloat:9.0) mantissaBits. 
    1.0 mantissaBits. 
    9.0 mantissaBits.  

o  mantissaWithHiddenBits
return the bits of my mantissa (incl. any hidden bit).
I.e. this returns the denormalized mantissaBits.
My bytes are stored LSB first.

Usage example(s):

    1.0 mantissaWithHiddenBits.                               4503599627370496
    (self fromFloat:1.0) mantissaWithHiddenBits.              4503599627370496
    1.0 asShortFloat mantissaWithHiddenBits.                  8388608
    (self fromFloat:1.0 asShortFloat) mantissaWithHiddenBits. 8388608

    10.0 mantissaWithHiddenBits.                               5629499534213120
    (self fromFloat:10.0) mantissaWithHiddenBits.              5629499534213120
    10.0 asShortFloat mantissaWithHiddenBits.                  10485760
    (self fromFloat:10.0 asShortFloat) mantissaWithHiddenBits. 10485760

    0.0125 mantissaWithHiddenBits.                               7205759403792794
    (self fromFloat:0.0125) mantissaWithHiddenBits.              7205759403792794
    0.0125 asShortFloat mantissaWithHiddenBits.                  13421773
    (self fromFloat:0.0125 asShortFloat) mantissaWithHiddenBits. 13421773

o  sign
return the sign of the receiver (-1, 0 or 1).
Notice: this returns 0 for a negative zero

Usage example(s):

     0.0 sign   => 0
     -0.0 sign  => 0
     2.0 sign   => 1
     -2.0 sign  => -1

     0.0 asIEEEFloat sign  => 0
     -0.0 asIEEEFloat sign => 0
     2.0 asIEEEFloat sign  => 1
     -2.0 asIEEEFloat sign => -1

o  signBit
return my sign bit (0 for positive, 1 for negative)

Usage example(s):

     0.0 asIEEEFloat signBit  0
     -0.0 asIEEEFloat signBit 1
     1.0 asIEEEFloat signBit  0
     -1.0 asIEEEFloat signBit 1

arithmetic
o  * aNumber
thisContext isRecursive ifTrue:[self halt].

o  + aNumber
thisContext isRecursive ifTrue:[self halt].

Usage example(s):

     (-2.0 asIEEEFloat)
     (2.0 asIEEEFloat)

     self assert:((4.0 asIEEEFloat) + (2.0 asIEEEFloat)) = (6.0 asIEEEFloat)   
     self assert:((4.0 asIEEEFloat) + (-2.0 asIEEEFloat)) = (2.0 asIEEEFloat)  
     self assert:((-4.0 asIEEEFloat) + (-2.0 asIEEEFloat)) = (-6.0 asIEEEFloat)  
     self assert:((-4.0 asIEEEFloat) + (2.0 asIEEEFloat)) = (-2.0 asIEEEFloat)  

     self assert:((2.0 asIEEEFloat) + (4.0 asIEEEFloat)) = (6.0 asIEEEFloat)   
     self assert:((2.0 asIEEEFloat) + (-4.0 asIEEEFloat)) = (-2.0 asIEEEFloat)  
     self assert:((-2.0 asIEEEFloat) + (-4.0 asIEEEFloat)) = (-6.0 asIEEEFloat)  
     self assert:((-2.0 asIEEEFloat) + (4.0 asIEEEFloat)) = (2.0 asIEEEFloat)  

     self assert:((IEEEFloat fromFloat:0.1) + (IEEEFloat fromFloat:-0.1)) = (IEEEFloat fromFloat:0.0)  
     self assert:((IEEEFloat fromFloat:-0.1) + (IEEEFloat fromFloat:0.1)) = (IEEEFloat fromFloat:0.0)  

     (self size:32 exponentSize:8 fromFloat:1.0) + (self size:32 exponentSize:8 fromFloat:2.0)
     (self size:64 exponentSize:11 fromFloat:1.0) + (self size:64 exponentSize:11 fromFloat:2.0)
     (self size:128 exponentSize:15 fromFloat:1.0) + (self size:128 exponentSize:15 fromFloat:2.0)
     (self size:512 exponentSize:23 fromFloat:1.0) + (self size:512 exponentSize:23 fromFloat:2.0)

o  - aNumber
thisContext isRecursive ifTrue:[self halt].

Usage example(s):

     self assert:((4.0 asIEEEFloat) - (2.0 asIEEEFloat)) = (2.0 asIEEEFloat)   
     self assert:((4.0 asIEEEFloat) - (-2.0 asIEEEFloat)) = (6.0 asIEEEFloat)  
     self assert:((-4.0 asIEEEFloat) - (-2.0 asIEEEFloat)) = (-2.0 asIEEEFloat)  
     self assert:((-4.0 asIEEEFloat) - (2.0 asIEEEFloat)) = (-6.0 asIEEEFloat)  

     self assert:((2.0 asIEEEFloat) - (4.0 asIEEEFloat)) = (-2.0 asIEEEFloat)   
     self assert:((2.0 asIEEEFloat) - (-4.0 asIEEEFloat)) = (6.0 asIEEEFloat)  
     self assert:((-2.0 asIEEEFloat) - (-4.0 asIEEEFloat)) = (2.0 asIEEEFloat)  
     self assert:((-2.0 asIEEEFloat) - (4.0 asIEEEFloat)) = (-6.0 asIEEEFloat)  

     self assert:((IEEEFloat fromFloat:0.1) - (IEEEFloat fromFloat:0.1)) = (IEEEFloat fromFloat:0.0)  
     self assert:((IEEEFloat fromFloat:0.1) - (IEEEFloat fromFloat:-0.1)) = (IEEEFloat fromFloat:0.2)  
     self assert:((IEEEFloat fromFloat:-0.1) - (IEEEFloat fromFloat:-0.1)) = (IEEEFloat fromFloat:0.0)  

o  / aNumber
thisContext isRecursive ifTrue:[self halt].

o  abs
return the absolute value of the receiver

Usage example(s):

     self assert:(IEEEFloat fromFloat:2.0) negated abs = (IEEEFloat fromFloat:2.0)  
     self assert:(IEEEFloat fromFloat:2.0) abs         = (IEEEFloat fromFloat:2.0) 
     self assert:(IEEEFloat fromFloat:-2.0) abs        = (IEEEFloat fromFloat:2.0) 

Usage example(s):

     0 asOctaFloat abs                 
     0 asOctaFloat negated abs                 
     10 asOctaFloat abs                 
     10 asOctaFloat negated abs                 
     -10 asOctaFloat abs                 

o  negated
return the receiver negated

Usage example(s):

     self assert:(IEEEFloat fromFloat:2.0) negated = (IEEEFloat fromFloat:-2.0) 
     self assert:(IEEEFloat fromFloat:2.0) negated negated = (IEEEFloat fromFloat:2.0) 
     self assert:(IEEEFloat fromFloat:-2.0) negated = (IEEEFloat fromFloat:2.0) 

Usage example(s):

     0 negated                 
     0.0 negated                
     0.0 asIEEEFloat negated negative  
     0.0 asIEEEFloat negated < 0   
     0.0 asIEEEFloat negated > 0   

coercing & converting
o  asFloat
return a regular float (i.e. an IEEE double) with my value

Usage example(s):

     |h q o l f|

     h := 1.0 asIEEEFloat:16.
     f := h asFloat.
     self assert:(f = 1.0).

     q := 1.0 asQuadFloat.
     f := h asFloat.
     self assert:(f = 1.0).

     o := 1.0 asOctaFloat.
     f := o asFloat.
     self assert:(f = 1.0).

     l := 1.0 asLargeFloat.
     f := l asFloat.
     self assert:(f = 1.0).

o  asFloatWithClass: floatClass
return a float instance of floatClass
with my value.
If floatClass is not an IEEE float class,
the class is asked for the conversion.

Usage example(s):

     (0 asFloat16) asFloatWithClass:ShortFloat      0.0
     (0 asIEEEFloat:8) asFloatWithClass:ShortFloat  0.0
     (4 asFloat16) asFloatWithClass:ShortFloat      4.0
     (4 asIEEEFloat:8) asFloatWithClass:ShortFloat  4.0
     (2 asIEEEFloat:8) asFloatWithClass:ShortFloat  2.0
     (1 asIEEEFloat:8) asFloatWithClass:ShortFloat  1.0
     (0.5 asIEEEFloat:8) asFloatWithClass:ShortFloat 0.5
     (4 asFloat16) asFloatWithClass:Float       4.0
     4.0 asLongFloat                            4.0
     (4 asFloat16) asFloatWithClass:LongFloat   4.0
     (4 asFloat16) asFloatWithClass:QuadFloat   4.0

     (4 asFloat16) asFloatWithClass:LargeFloat  4.0

o  asInteger
return an integer with same value - might truncate towards zero

Usage example(s):

     1.0 asQuadFloat asInteger        1
     2.0 asQuadFloat asInteger        2
     0.5 asQuadFloat asInteger        0
     -0.5 asQuadFloat asInteger       0 
     32.0 asQuadFloat asInteger       32 
     -32.0 asQuadFloat asInteger      -32  
     1e20 asQuadFloat asInteger       100000000000000000000 - exact
     1e20 asQuadFloat squared asInteger          10000000000000000000000000000000000000000 - exact
     1e20 asQuadFloat squared squared asInteger  - inexact      
     1e20 asOctaFloat squared squared asInteger  - exact      

Usage example(s):

     1.0 asOctaFloat asInteger        
     2.0 asOctaFloat asInteger        
     0.5 asOctaFloat asInteger        
     -0.5 asOctaFloat asInteger        
     32.0 asOctaFloat asInteger        
     -32.0 asOctaFloat asInteger        
     1e20 asOctaFloat asInteger                  - exact
     1e20 asOctaFloat squared asInteger          - exact
     1e20 asOctaFloat squared squared asInteger  - exact      
     1e20 asOctaFloat squared squared squared asInteger  - inexact      

Usage example(s):

     1.0 asLargeFloat asInteger        
     2.0 asLargeFloat asInteger        
     0.5 asLargeFloat asInteger        
     -0.5 asLargeFloat asInteger        
     32.0 asLargeFloat asInteger        
     -32.0 asLargeFloat asInteger        
     (1e20 asLargeFloatPrecision:500) asInteger                  - exact
     (1e20 asLargeFloatPrecision:500) squared asInteger          - exact
     (1e20 asLargeFloatPrecision:500) squared squared asInteger  - exact      
     (1e20 asLargeFloatPrecision:500) squared squared squared asInteger  - exact      

Usage example(s):

     1.0 asInteger        
     2.0  asInteger        
     0.5  asInteger        
     -0.5  asInteger        
     32.0  asInteger        
     -32.0  asInteger        

o  asLongFloat
return a long float (i.e. an IEEE extended precision) with my value

Usage example(s):

     (4 asFloat16) asFloat
     (4 asIEEEFloat:16) asFloat    
     (10 asIEEEFloat:16) asFloat   
     (10 asIEEEFloat:16) asLongFloat  

     (4 asIEEEFloat:8) asFloat      4.0
     (10 asIEEEFloat:8) asFloat     10.0
     (10 asIEEEFloat:8) asLongFloat 10.0 

o  asShortFloat
return a short float (i.e. an IEEE single) with my value

Usage example(s):

     (4 asFloat16) asFloat
     (4 asIEEEFloat:16) asFloat  
     (10 asIEEEFloat:16) asFloat  
     (10 asIEEEFloat:16) asShortFloat  

Usage example(s):

     |h q o l f|

     h := 1.0 asIEEEFloat:16.
     f := h asShortFloat.
     q := 1.0 asQuadFloat.
     f := h asShortFloat.
     o := 1.0 asOctaFloat.
     f := o asShortFloat.
     l := 1.0 asLargeFloat.
     f := l asShortFloat

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

comparing
o  < aNumber
thisContext isRecursive ifTrue:[self halt].

o  = aNumber
(comment from inherited method)
Compare the receiver with the argument and return true if the
receiver is equal to the argument. Otherwise return false.

double dispatching
o  differenceFromIEEEFloat: anIEEEFloat
anIEEEFloat - self

o  equalFromIEEEFloat: anIEEEFloat
}

o  lessFromIEEEFloat: anIEEEFloat
true if anIEEEFloat < self

o  productFromIEEEFloat: anIEEEFloat
anIEEEFloat * self

o  productFromInteger: anInteger
anIEEEFloat * self

o  quotientFromIEEEFloat: anIEEEFloat
anIEEEFloat / self

o  remainderFromIEEEFloat: anIEEEFloat
anIEEEFloat rem: self

o  sumFromIEEEFloat: anIEEEFloat
anIEEEFloat + self

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

Usage example(s):

x := self coerce:(self asFloat ln).

Usage example(s):

     Number trapInfinity:[ 0.0 ln ]   
     Number trapInfinity:[ 0.0 asIEEEFloat ln ]    
     1.0 asIEEEFloat ln         

     2.7 asIEEEFloat ln
     100 asIEEEFloat ln
     3.0 asIEEEFloat ln printfPrintString:'%10.8f'

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

Usage example(s):

     10.0 ln                            2.30258509299405
     10.0 asIEEEFloat ln                2.302585
     10.0 asShortFloat ln               2.302585
     10.0 asShortFloat asIEEEFloat ln   2.30258509299405
     10.0 asOctaFloat ln                
     OctaFloat ln10                     2.302585092994045684017991454684364207601101488628772976033327900967572609

     (10.0 asShortFloat coerce:Float ln10)               2.302585
     (10.0 asShortFloat asIEEEFloat coerce:Float ln10)   

     (10.0 asShortFloat log10)                1.0
     (10.0 asShortFloat asIEEEFloat log10)   
     (10.0 asShortFloat asIEEEFloat ln)   

     (10.0 log10)                1.0
     (10.0 asIEEEFloat log10)    

private accessing
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  digitBytes: bytes MSB: bytesAreMSB

o  exponentSize: numBitsInExponent

** This method must be redefined in concrete classes (subclassResponsibility) **

o  setFraction: normalizedFractionArg biasedExponent: biasedExponentArg signBit: signBit
}

Usage example(s):

     (self size:64 exponentSize:11) setFraction:0 biasedExponent:(Float eBias) signBit:0             -> 1.0
     (self size:64 exponentSize:11) setFraction:0 biasedExponent:(Float eBias+1) signBit:0           -> 2.0 
     (self size:64 exponentSize:11) setFraction:0 biasedExponent:(Float eBias+Float emax) signBit:0  -> 8.988466e307
     (self size:64 exponentSize:11) setFraction:0 biasedExponent:0 signBit:0                         -> 0.0

     (self size:64 exponentSize:11) setFraction:0 biasedExponent:-1 signBit:0                           -> error
     (self size:64 exponentSize:11) setFraction:0 biasedExponent:(Float eBias+Float emax+2) signBit:0   -> error / inf if proceeded
     (self size:64 exponentSize:11) setFraction:0 biasedExponent:(Float eBias+Float emax+2) signBit:1   -> error / -inf if proceeded
     (self size:64 exponentSize:11) setFraction:0 biasedExponent:(Float eBias+Float emin-1) signBit:0   -> 0.0
     (self size:64 exponentSize:11) setFraction:0 biasedExponent:(Float eBias+Float emin-1) signBit:1   -> -0.0

     (self size:128 exponentSize:15) setFraction:0 biasedExponent:(QuadFloat eBias) signBit:0             -> 1.0
     (self size:128 exponentSize:15) setFraction:0 biasedExponent:(QuadFloat eBias+1) signBit:0           -> 2.0 
     (self size:128 exponentSize:15) setFraction:0 biasedExponent:(QuadFloat eBias+QuadFloat emax) signBit:0  -> 5.94865747e4931
     (self size:128 exponentSize:15) setFraction:0 biasedExponent:0 signBit:0                             -> 0.0

o  setMantissa: mantissaBitsInclHidden exponent: exponent signBit: signBit
construct my bits.
Notice that the incoming mantissaBits must be denormalized (have the highest bit set)

Usage example(s):

     (self size:32 exponentSize:11) 
        setMantissa:(1.0 mantissaWithHiddenBits) exponent:(1.0 exponent) sign:0

     (self size:16 exponentSize:4) 
        setMantissa:(1.0 mantissaWithHiddenBits) exponent:(1.0 exponent) sign:0

o  setMantissaBits: mantissaBitsExclHidden exponentBits: exponentBits signBit: signBit
low level construct my bits.
Notice that the incoming mantissaBits must be raw normalized,
and exponentBits must be biased.
Used to construct denormalized or non-finite instances

o  setSignBit: aBit
destructively set my sign bit (0 for positive, 1 for negative)

Usage example(s):

     0.0 asIEEEFloat copy setSignBit:1 

o  setValueFromFloat: aFloat
deconstruct the float arg and construct my bits

Usage example(s):

     self size:16 exponentSize:4 fromFloat:1.0
     self size:32 exponentSize:8 fromFloat:1.0
     self size:64 exponentSize:11 fromFloat:1.0
     self size:80 exponentSize:15 fromFloat:1.0
     self size:128 exponentSize:15 fromFloat:1.0
     self size:256 exponentSize:19 fromFloat:1.0
     self size:512 exponentSize:23 fromFloat:1.0

     self size:256 exponentSize:19 fromFloat:2.0
     self size:512 exponentSize:23 fromFloat:2.0

     (IEEEFloat size:32 exponentSize:8) setValueFromFloat:ShortFloat infinity
     (IEEEFloat size:32 exponentSize:8) setValueFromFloat:ShortFloat negativeInfinity
     (IEEEFloat size:32 exponentSize:8) setValueFromFloat:ShortFloat NaN
     (IEEEFloat size:64 exponentSize:11) setValueFromFloat:ShortFloat infinity
     (IEEEFloat size:64 exponentSize:11) setValueFromFloat:ShortFloat negativeInfinity
     (IEEEFloat size:64 exponentSize:11) setValueFromFloat:ShortFloat NaN

o  setValueFromLimitedPrecisionReal: aFloat
deconstruct the float arg and construct my bits.
Assumes that aFloat is in IEEE format.
If aFloat's mantissa has more bits, the result is rounded

queries
o  decimalPrecision
Answer how many digits of accuracy this instance supports

Usage example(s):

     1.0 decimalPrecision                  -> 15
     1.0 asShortFloat decimalPrecision     -> 7

     1.0 asIEEEFloat decimalPrecision      -> 15
     1.0 asShortFloat asIEEEFloat decimalPrecision -> 7

     (1.0 asIEEEFloat:64) decimalPrecision -> 15
     (1.0 asIEEEFloat:32) decimalPrecision -> 7
     (1.0 asIEEEFloat:16) decimalPrecision -> 3
     (1.0 asIEEEFloat:8) decimalPrecision  -> 1

o  emax
The largest exponent value allowed by instances like this.
The computation below assumes standard IEEE format.
This is implemented on the instance side,
because of IEEEFloat, which has instance-specific representation.

Usage example(s):

     Float emax       -> 1023
     ShortFloat emax  -> 127
     LongFloat emax   -> 16383
     QuadFloat emax   -> 16383
     OctaFloat emax   -> 262143
     QDouble emax     -> 1023

o  exponent
extract a normalized float's (unbiased) exponent.
This is a fallback for systems which do not provide frexp in their math lib,
and also for error reporting (NaN or Inf).
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):

Extract the sign and the biased exponent 

Usage example(s):

     0.3 asFloat exponent        
     0.3 asShortFloat exponent  
     0.3 asLongFloat exponent  
     0.3 asIEEEFloat exponent  
     0.3 asQuadFloat exponent    

     0.0 exponent      0
     1.0 exponent      1
     2.0 exponent      2
     3.0 exponent      2
     4.0 exponent      3
     0.5 exponent      0
     0.4 exponent      -1
     0.25 exponent     -1
     0.25 asQuadFloat exponent     -1
     0.00000011111 exponent  -23 

     0.0 nextFloat exponent             -1073
     0.0 asIEEEFloat nextFloat exponent -1073
     0.0 nextFloat asIEEEFloat exponent -1073
     0.0 nextFloat asQuadFloat exponent -1073

     0.0 asQuadFloat nextFloat exponent -16493
     0.0 asOctaFloat nextFloat exponent -262377
     0.0 asLargeFloat nextFloat exponent -202

o  fmax
the largest finite value which can be represented by instances with the same
layout (i.e. same number of exponent bits) as an instance with my layout

Usage example(s):

     1.0 fmax               -> 1.79769313486232E+308
     1.0 asShortFloat fmax  -> 3.402823e+38
     1.0 asLongFloat fmax   -> 1.189731495357231765e+4932
     1.0 asQuadFloat fmax printfPrintString:'%g' -> '1.189731495e4932'  
     1.0 asOctaFloat fmax printfPrintString:'%g' -> '1.61132571748e78913'
     (1.0 asIEEEFloat:8) fmax printfPrintString:'%g' -> '239.999999999999'  

     1.0 fmax digitBytes = 1.0 asIEEEFloat fmax digitBytes                              -> true
     1.0 asShortFloat fmax digitBytes = 1.0 asShortFloat asIEEEFloat fmax digitBytes    -> true

o  fmaxDenormalized
the largest denormalized value which can be represented by instances with the same
layout (i.e. same number of exponent bits) as an instance with my layout

Usage example(s):

     1.0 fmin               ->   2.2250738585072e-308
     1.0 fminDenormalized   ->   4.94065645841247e-324

     1.0 asShortFloat fmin              ->   1.175494e-38
     1.0 asShortFloat fminDenormalized  ->   1.401298e-45

     1.0 fmin digitBytes = 1.0 asIEEEFloat fmin digitBytes                         -> true
     1.0 fminDenormalized digitBytes = 1.0 asIEEEFloat fminDenormalized digitBytes -> true                              -> true

     1.0 asShortFloat fmin digitBytes = 1.0 asShortFloat asIEEEFloat fmin digitBytes    -> true
     1.0 asShortFloat fminDenormalized digitBytes = 1.0 asShortFloat asIEEEFloat fminDenormalized digitBytes    -> true

     Float NaN digitBytes  = Float NaN asIEEEFloat digitBytes                           -> true
     Float infinity digitBytes = Float infinity asIEEEFloat digitBytes                  -> true
     Float negativeInfinity digitBytes = Float negativeInfinity asIEEEFloat digitBytes  -> true           

     1.0 fmin printfPrintString:'%g'              -> '2.22507e-308'  
     1.0 asShortFloat fmin printfPrintString:'%g' -> '1.17549e-38'
     1.0 asQuadFloat fmin printfPrintString:'%g'  -> '1.054121244e-4931'  
     1.0 asOctaFloat fmin printfPrintString:'%g'  -> '3.27157837924e-78913'  
     1.0 asOctaFloat fmin  
     1.0 asOctaFloat fmaxDenormalized  

o  fmin
the smallest normalized non-zero value which can be represented by instances with the same
layout (i.e. same number of exponent bits) as an instance with my layout

Usage example(s):

     1.0 fmin                                                   ->   2.2250738585072E-308
     1.0 fmin digitBytes = 1.0 asIEEEFloat fmin digitBytes                              -> true
     1.0 fmax digitBytes = 1.0 asIEEEFloat fmax digitBytes                              -> true
     1.0 asShortFloat fmin digitBytes = 1.0 asShortFloat asIEEEFloat fmin digitBytes    -> true

     Float NaN digitBytes  = Float NaN asIEEEFloat digitBytes                           -> true
     Float infinity digitBytes = Float infinity asIEEEFloat digitBytes                  -> true
     Float negativeInfinity digitBytes = Float negativeInfinity asIEEEFloat digitBytes  -> true           

     1.0 fmin printfPrintString:'%g'              -> '2.22507e-308'  
     1.0 asShortFloat fmin printfPrintString:'%g' -> '1.17549e-38'
     1.0 asQuadFloat fmin printfPrintString:'%g'  -> '1.054121244e-4931'  
     1.0 asOctaFloat fmin printfPrintString:'%g'  -> '3.27157837924e-78913'  

o  fminDenormalized
the smallest non-zero value which can be represented by denormalized instances with the same
layout (i.e. same number of exponent bits) as an instance with my layout

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  isNegativeZero
IEEE has two zeros

Usage example(s):

     0.0 asIEEEFloat isZero            true
     0.0 asIEEEFloat isNegativeZero    false
     -0.0 asIEEEFloat isZero           true
     -0.0 asIEEEFloat isNegativeZero   true

o  mantissa
extract a normalized float's mantissa.
That is a float of the same type as the receiver,
such that:
(f mantissa) * (2 ^ f exponent) = f
This is a fallback for systems which do not provide frexp in their math lib,
and also for error reporting (NaN or Inf).

Usage example(s):

     1.0 mantissa               -> 0.5 
     1.0 asIEEEFloat mantissa   -> 0.5 

     0.3 asFloat mantissa       0.6
     0.3 asShortFloat mantissa  0.6
     0.3 asLongFloat mantissa   0.5999999999999999778
     0.3 asQDouble mantissa     0.6
     0.3 asQuadFloat mantissa   0.6
     0.3 asOctaFloat mantissa   0.6
     0.3 asLargeFloat mantissa  0.6

     (0.3 asIEEEFloat) mantissa      -> 0.6 
     (0.3 asIEEEFloat:24) mantissa   -> 0.5 
     (0.3 asIEEEFloat:128) mantissa  -> 0.5 

     0.0 asLongFloat mantissa       0.0
     0.0 asQuadFloat mantissa       0.0
     0.0 asOctaFloat mantissa       0.0
     0.0 asLargeFloat mantissa      0.0

     Float fmin mantissa           0.5
     QuadFloat fmin mantissa       0.5
     OctaFloat fmin mantissa       0.5

     Float fminDenormalized mantissa           0.5
     QuadFloat fminDenormalized mantissa       0.5
     OctaFloat fminDenormalized mantissa       0.5

     10.0 asIEEEFloat exponent                4
     10.0 asIEEEFloat mantissa                0.625

     16.400000 mantissa             0.5125
     16.400000 exponent             5
     16.400000 asQuadFloat mantissa 0.5125
     16.400000 asQuadFloat exponent 5
     16.400000 asOctaFloat mantissa 0.5125
     16.400000 asOctaFloat exponent 5

     Float fmin mantissa            0.5
     Float fmin exponent            -1021
     Float fmin asIEEEFloat mantissa            0.5
     Float fmin asIEEEFloat exponent            -1021
     0.5 asLargeFloat timesTwoPower:-1021 

     (Float fmin * 10) mantissa            0.625
     (Float fmin * 10) exponent            -1018
     (Float fmin * 10) asIEEEFloat mantissa   0.625
     (Float fmin * 10) asIEEEFloat exponent   -1018
     0.625 asLargeFloat timesTwoPower:-1018 

     Float fminDenormalized mantissa            0.5
     Float fminDenormalized exponent            -1073
     Float fminDenormalized asIEEEFloat mantissa            0.5
     Float fminDenormalized asIEEEFloat exponent            -1073
     0.5 asLargeFloat timesTwoPower:-1073   

     (Float fminDenormalized * 10) mantissa            0.625
     (Float fminDenormalized * 10) exponent            -1070
     (Float fminDenormalized * 10) asIEEEFloat mantissa   0.625
     (Float fminDenormalized * 10) asIEEEFloat exponent   -1070
     0.625 asLargeFloat timesTwoPower:-1070  4.9406564584125e-323 


     9.0 asIEEEFloat exponent   
     9.0 asIEEEFloat mantissa   
     -9.0 asIEEEFloat exponent   
     -9.0 asIEEEFloat mantissa   

     10.0 asShortFloat asIEEEFloat exponent   4
     10.0 asShortFloat asIEEEFloat mantissa   

     10.0q asIEEEFloat exponent        4
     10.0q asIEEEFloat mantissa   

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

^ (self negated nextFloat:nUlps negated) negated

Usage example(s):

0.5+0.25+0.125 
       -> '0 0111111 1110 1100 00000000 00000000 00000000 00000000 00000000 00000000'

    Float basicNew
       basicAt:1 put:255;
       basicAt:2 put:255;
       basicAt:3 put:255;
       basicAt:4 put:255;
       basicAt:5 put:255;
       basicAt:6 put:255;
       basicAt:7 put:2r11101111;
       basicAt:8 put:2r00111111;
       inspect;
       nextFloat

    1.0 asIEEEFloat nextFloat:1 
    1.0 nextFloat:1
    0.0 asIEEEFloat nextFloat:1

    0.0 asOctaFloat nextFloat:-1.
    1.0 asOctaFloat nextFloat:-1.

    1.0 asIEEEFloat fmaxDenormalized nextFloat:-1

    QuadFloat fmaxDenormalized   
    QuadFloat fmaxDenormalized nextFloat:1 
    QuadFloat fmin nextFloat:-1   
    QuadFloat fmin                

o  numBitsInMantissa
answer the number of bits in the mantissa (the significant).
any hidden bits are not counted.
This is an IEEE float,
where n*8 - 1 - exponentSize (n=nr of bytes)
bits are available in the mantissa.
The hidden bit is not counted here.
s ee...ee mmm...mmm

o  precision
answer the precision (the number of valid bits in the mantissa) of my elements (in bits)
If my elments are IEEE floats, where only the fraction from the normalized mantissa is stored,
there will be a hidden bit and the mantissa will be actually represented by 1 more binary digits
(i.e. the number returned is 1 plus the actual number of bits stored)
the hidden bit is included here

o  radix
Answer the exponent's radix

o  unity
return a one which has the same layout as myself

Usage example(s):

     1.0 asIEEEFloat unity digitBytes = 1.0 digitBytes  
     1.0 asShortFloat asIEEEFloat unity digitBytes = 1.0 asShortFloat digitBytes  

o  zero
return a zero which has the same layout as myself

Usage example(s):

     1.0 asIEEEFloat zero digitBytes = 0.0 digitBytes  
     1.0 asShortFloat asIEEEFloat zero digitBytes = 0.0 asShortFloat digitBytes  

testing
o  isFinite
return true, if the receiver is a finite float (not NaN and not +/-INF)

o  isInfinite
return true, if the receiver is an infinite float (+/-INF)

o  isNaN
return true, if the receiver is an invalid float (NaN - not a number)

Usage example(s):

    Float NaN isNaN      -> true
    Float NaN isFinite   -> false
    Float NaN isInfinite -> false

    Float NaN asIEEEFloat isNaN      -> true
    Float NaN asIEEEFloat isFinite   -> false
    Float NaN asIEEEFloat isInfinite -> false

    Float infinity isNaN      -> false
    Float infinity isFinite   -> false
    Float infinity isInfinite -> true

    Float infinity asIEEEFloat isNaN      -> false
    Float infinity asIEEEFloat isFinite   -> false
    Float infinity asIEEEFloat isInfinite -> true

o  isZero
return true, if the receiver is zero

Usage example(s):

     0.0 negated = 0.0
     0.0 negated isZero
     0.0 asIEEEFloat isZero
     0.0 asIEEEFloat negated isZero   
     0.0 asIEEEFloat = 0.0        
     0.0 asIEEEFloat negated = 0.0   

o  negative
return true if the receiver is less than zero.

Usage example(s):

if any other bit is set, then it's not a negative zero

Usage example(s):

     -1.0 asIEEEFloat negative                    true
     0.0 asIEEEFloat negative                     false
     -0.0 asIEEEFloat negative                    false
     Float infinity asIEEEFloat negative          false
     Float negativeInfinity asIEEEFloat negative  true
     Float NaN asIEEEFloat negative               false



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 07 Sep 2024 23:25:54 GMT