HalfFloat.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5444 800ebf99147b
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5444
800ebf99147b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5374
diff changeset
     1
"{ Encoding: utf8 }"
800ebf99147b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5374
diff changeset
     2
5374
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
     3
"
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
     4
 COPYRIGHT (c) 2018 by eXept Software AG
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
     5
              All Rights Reserved
5335
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
     6
5374
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
     7
 This software is furnished under a license and may be used
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
     8
 only in accordance with the terms of that license and with the
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
     9
 inclusion of the above copyright notice.  This software may not
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    10
 be provided or otherwise made available to, or used by, any
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    11
 other person.  No title to or ownership of the software is
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    12
 hereby transferred.
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    13
"
5277
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
"{ NameSpace: Smalltalk }"
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
LimitedPrecisionReal variableByteSubclass:#HalfFloat
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Magnitude-Numbers'
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!HalfFloat class methodsFor:'documentation'!
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
5374
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    27
copyright
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    28
"
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    29
 COPYRIGHT (c) 2018 by eXept Software AG
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    30
              All Rights Reserved
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    31
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    32
 This software is furnished under a license and may be used
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    33
 only in accordance with the terms of that license and with the
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    34
 inclusion of the above copyright notice.  This software may not
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    35
 be provided or otherwise made available to, or used by, any
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    36
 other person.  No title to or ownership of the software is
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    37
 hereby transferred.
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    38
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    39
"
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    40
!
3ef7cedd7dac #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5335
diff changeset
    41
5277
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
documentation
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
"
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    HalfFloats represent rational numbers with very very limited precision.
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    There are no instances of it to be created - halfFloats are only possibly stored
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    inside instancs of HalfFloatArray, which are presented as floats or shortFloats when accessd.
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    However, this class is provided for queries about precision, bits in mantissa etc.
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    Representation:
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
            16bit single precision IEEE floats
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
            10 bit fraction + 1 hidden bit, providing a precision of 11bits,
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
            5 bit exponent,
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
            6 decimal digits (approx.)
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    [author:]
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
        Claus Gittinger
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    [see also:]
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
        Number
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
        Float LongFloat Fraction FixedPoint Integer Complex
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
        HalfFloatArray FloatArray DoubleArray
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
"
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
! !
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
!HalfFloat class methodsFor:'queries'!
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
eBias
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    "Answer the exponent's bias; 
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
     that is the offset of the zero exponent when stored"
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    ^ 15
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
!
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
emax
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    ^ 15
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
!
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
emin
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    ^ -14
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
!
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
numBitsInExponent
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    "answer the number of bits in the exponent
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
     This is an IEEE float, where 4 bits are available:
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
        seeeemmm mmmmmmmm
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    "
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    ^ 4
5335
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
    91
!
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
    92
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
    93
numBitsInMantissa
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
    94
    "answer the number of bits in the mantissa (the significant).
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
    95
     This is an IEEE binary16, where 11 bits are available (the hidden bit is not counted here):
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
    96
        seeeemmm mmmmmmmm
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
    97
    "
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
    98
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
    99
    ^ 11
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
   100
!
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
   101
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
   102
radix
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
   103
    "answer the radix of a Float's exponent
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
   104
     This is an IEEE float, which is represented as binary"
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
   105
82756240a52d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5277
diff changeset
   106
    ^ 2 
5277
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
! !
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
!HalfFloat class methodsFor:'documentation'!
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
version_CVS
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    ^ '$Header$'
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
! !
dc8d7dd2d811 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114