RegressionTests__IEEEFloatTest.st
author Claus Gittinger <cg@exept.de>
Tue, 03 Dec 2019 23:36:19 +0100
changeset 2462 695bfe3c2283
parent 2459 8754c5f80a6f
child 2464 fccea2dd0aef
permissions -rw-r--r--
#QUALITY by cg class: RegressionTests::IEEEFloatTest changed: #test05_Comparing #test07_Truncation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/regression' }"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"{ NameSpace: RegressionTests }"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
TestCase subclass:#IEEEFloatTest
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	instanceVariableNames:''
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	classVariableNames:''
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	poolDictionaries:''
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
	category:'tests-Regression-Numbers'
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
!IEEEFloatTest class methodsFor:'helpers'!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
actualPrecisionOf:aFloatClass
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
    "get the actual number of valid bits in the mantissa.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
     This does a real test (i.e. does not believe the compiled-in ifdefs)"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
    |one x count|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
    one := aFloatClass unity.  "/ 1.0 in this class
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
    x := one.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
    count := 0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
    [one + x > one] whileTrue:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
        x := x / 2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
        count := count + 1.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
    ^ count
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
     self actualPrecisionOf:ShortFloat
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
     self actualPrecisionOf:Float
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
     self actualPrecisionOf:LongFloat
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
! !
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
!IEEEFloatTest methodsFor:'tests'!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
test00_Precision
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    "computed precision vs. assumed precision."
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    "/ verify IEEE values
2458
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
    44
    self assert:((IEEEFloat fromFloat:1.0) radix == 2).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
    45
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    self assert:((IEEEFloat fromFloat:1.0) emin == 1.0 emin).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    self assert:((IEEEFloat fromFloat:1.0) emax == 1.0 emax).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    self assert:((IEEEFloat fromFloat:1.0) eBias == 1.0 eBias).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    self assert:((IEEEFloat fromFloat:1.0 asShortFloat) emin == 1.0 asShortFloat emin).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    self assert:((IEEEFloat fromFloat:1.0 asShortFloat) emax == 1.0 asShortFloat emax).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    self assert:((IEEEFloat fromFloat:1.0 asShortFloat) eBias == 1.0 asShortFloat eBias).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    self assert:((IEEEFloat fromFloat:1.0 asLongFloat) emin == 1.0 asLongFloat emin).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    self assert:((IEEEFloat fromFloat:1.0 asLongFloat) emax == 1.0 asLongFloat emax).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    self assert:((IEEEFloat fromFloat:1.0 asLongFloat) eBias == 1.0 asLongFloat eBias).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
     self basicNew test00_Precision
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
test01_Nan
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    "NaN in all avaliable formats."
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    |shouldBeNaN|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    shouldBeNaN := 0.0 asIEEEFloat uncheckedDivide: 0.0 asIEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    self assert:( shouldBeNaN isNaN ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    self assert:( shouldBeNaN isFinite not ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    "/ but these are:
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    self assert:( shouldBeNaN + 1 ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    self assert:( shouldBeNaN + 1.0 ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    self assert:( shouldBeNaN + 1.0 asShortFloat ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    self assert:( shouldBeNaN + 1.0 asLongFloat ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    self assert:( shouldBeNaN - 1 ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    self assert:( shouldBeNaN - 1.0 ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    self assert:( shouldBeNaN - 1.0 asShortFloat ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    self assert:( shouldBeNaN - 1.0 asLongFloat ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    self assert:( shouldBeNaN * 1 ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    self assert:( shouldBeNaN * 1.0 ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    self assert:( shouldBeNaN * 1.0 asShortFloat ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    self assert:( shouldBeNaN * 1.0 asLongFloat ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    self assert:( shouldBeNaN * 2 ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    self assert:( shouldBeNaN * 2.0 ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    self assert:( shouldBeNaN * 2.0 asShortFloat ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    self assert:( shouldBeNaN * 2.0 asLongFloat ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    self assert:( shouldBeNaN / 1 ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    self assert:( shouldBeNaN / 1.0 ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    self assert:( shouldBeNaN / 1.0 asShortFloat ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    self assert:( shouldBeNaN / 1.0 asLongFloat ) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
     self basicNew test01_Nan
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    "Modified: / 20-06-2017 / 14:00:08 / cg"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
test02_Inf
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    "Infinity in all avaliable formats."
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    |check posInf negInf|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    check :=
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
        [:v1 :v2 |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
            posInf := v1 uncheckedDivide: v2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
            self assert:( posInf isMemberOf:v1 class ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
            self assert:( posInf isNaN not ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
            self assert:( posInf isFinite not ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
            self assert:( posInf isInfinite ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
            self assert:( posInf positive ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
            self assert:( posInf negative not ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
            self assert:( posInf isNegativeInfinity not).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
            self assert:( posInf isPositiveInfinity ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
            negInf := v1 negated uncheckedDivide: v2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
            self assert:( negInf isMemberOf:v1 class ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
            self assert:( negInf isNaN not ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
            self assert:( negInf isFinite not ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
            self assert:( negInf isInfinite ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
            self assert:( negInf positive not).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
            self assert:( negInf negative ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
            self assert:( negInf isNegativeInfinity ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
            self assert:( negInf isPositiveInfinity not ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
            self assert:( negInf + negInf = negInf).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
            self assert:( posInf + posInf = posInf).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
            self assert:( negInf + posInf) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
            self assert:( posInf + negInf) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
            self assert:( negInf - posInf = negInf).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
            self assert:( negInf - negInf) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
            self assert:( posInf - negInf = posInf).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
            self assert:( posInf - posInf) isNaN.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
            self assert:( posInf + v1) = posInf.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
            self assert:( posInf - v1) = posInf.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
            self assert:( negInf + v1) = negInf.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
            self assert:( negInf - v1) = negInf.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
        ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    check value: 1.0 value: 0.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    check value: 1.0 asShortFloat value: 0.0 asShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
    check value: 1.0 asLongFloat value: 0.0 asLongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
"/ these are not guaranteed to work with uncheckedDivide...
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
"/    check value: 1.0 value: 0.0 asShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
"/    check value: 1.0 value: 0.0 asLongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
"/
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
"/    check value: 1.0 asShortFloat value: 0.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
"/    check value: 1.0 asShortFloat value: 0.0 asLongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
"/
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
"/    check value: 1.0 asLongFloat value: 0.0 asShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
"/    check value: 1.0 asLongFloat value: 0.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    { Float . ShortFloat . LongFloat }
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    do:[:cls |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
        posInf := cls infinity.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
        self assert:( posInf isInfinite ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
        self assert:( posInf isFinite not ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
        self assert:( posInf > 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
        self assert:( posInf >= 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
        self assert:( posInf < 0 ) not.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
        self assert:( posInf <= 0 ) not.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
        negInf := cls negativeInfinity.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
        self assert:( negInf isInfinite ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
        self assert:( negInf isFinite not ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
        self assert:( negInf < 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
        self assert:( negInf <= 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
        self assert:( negInf > 0 ) not.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
        self assert:( negInf >= 0 ) not.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
        self assert:(posInf isNaN not). 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
        self assert:(posInf isFinite not). 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
        self assert:(posInf isInfinite). 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
        self assert:(negInf isNaN not). 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
        self assert:(negInf isFinite not). 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
        self assert:(negInf isInfinite). 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
        self assert:(posInf negated = negInf). 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
        self assert:(negInf negated = posInf). 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
     self basicNew test02_Inf
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    "Modified: / 20-06-2017 / 14:03:08 / cg"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
    "Modified: / 10-06-2019 / 23:45:05 / Claus Gittinger"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
test03_Conversion
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    self assert:( 1.0 asTrueFraction == 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    self assert:( 2.0 asTrueFraction == 2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    self assert:( 4.0 asTrueFraction == 4 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
    self assert:( 8.0 asTrueFraction == 8 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    self assert:( 16.0 asTrueFraction == 16 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    self assert:( 1048576.0 asTrueFraction == 1048576 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
    self assert:( 0.5 asTrueFraction = (1/2) ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    self assert:( 0.25 asTrueFraction = (1/4) ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    self assert:( 0.125 asTrueFraction = (1/8) ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    self assert:( 1.0 asShortFloat asTrueFraction == 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    self assert:( 2.0 asShortFloat asTrueFraction == 2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    self assert:( 4.0 asShortFloat asTrueFraction == 4 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
    self assert:( 8.0 asShortFloat asTrueFraction == 8 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
    self assert:( 16.0 asShortFloat asTrueFraction == 16 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
    self assert:( 1048576.0 asShortFloat asTrueFraction == 1048576 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
    self assert:( 0.5 asShortFloat asTrueFraction = (1/2) ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
    self assert:( 0.25 asShortFloat asTrueFraction = (1/4) ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    self assert:( 0.125 asShortFloat asTrueFraction = (1/8) ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    self assert:( 1.0 asLongFloat asTrueFraction == 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
    self assert:( 2.0 asLongFloat asTrueFraction == 2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
    self assert:( 4.0 asLongFloat asTrueFraction == 4 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    self assert:( 8.0 asLongFloat asTrueFraction == 8 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
    self assert:( 16.0 asLongFloat asTrueFraction == 16 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    self assert:( 1048576.0 asLongFloat asTrueFraction == 1048576 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
    self assert:( 0.5 asLongFloat asTrueFraction = (1/2) ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    self assert:( 0.25 asLongFloat asTrueFraction = (1/4) ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    self assert:( 0.125 asLongFloat asTrueFraction = (1/8) ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
    self assert: ((5/9) asFloat     - 0.555555555555) abs < 0.0000000001.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    self assert: ((5/9) asLongFloat - 0.555555555555) abs < 0.0000000001.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    self assert: ((Fraction basicNew setNumerator:500000000000 denominator:900000000000)
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
			asLongFloat - 0.555555555555) abs <  0.000000000001.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    self assert: ((Fraction basicNew setNumerator:500000000001 denominator:900000000000)
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
			asLongFloat - 0.555555555555) abs >= 0.000000000001.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    "/ under windows, a longFloat has only 10bytes with 64 bits precision
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
    OperatingSystem isMSWINDOWSlike ifFalse:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
	self assert: (8901234567890123456 asLongFloat asInteger = 8901234567890123456).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
	self assert: (-8901234567890123456 asLongFloat asInteger = -8901234567890123456).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
    self assert: (89012345678901234567 asLongFloat = 89012345678901234567).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
    self assert: (-89012345678901234567 asLongFloat = -89012345678901234567).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    self assert: (89012345678901234567 negated asLongFloat = -89012345678901234567).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
    self assert: ((89012345678901234567 / 123456789123456789) asLongFloat  - (89012345678901234567 asLongFloat / 123456789123456789 asLongFloat) ) abs < 0.000000000001.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
    self assert: ((-89012345678901234567 / 123456789123456789) asLongFloat - (-89012345678901234567 asLongFloat / 123456789123456789 asLongFloat)) abs < 0.000000000001.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
     self basicNew test03_Conversion
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    "Modified: / 09-08-2011 / 21:01:57 / cg"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
test04_Arithmetic
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
    self assert:( 1.0 asIEEEFloat + 1.0) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    self assert:( 1.0 asIEEEFloat + 1.0 asIEEEFloat) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
    self assert:( 1.0 asIEEEFloat + 1.0 asShortFloat) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
    self assert:( 1.0 asIEEEFloat + 1.0 asLongFloat) class == IEEEFloat.
2448
d6af1cf98136 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   266
    "/ self assert:( 1.0 asIEEEFloat + 1) class == IEEEFloat.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
2448
d6af1cf98136 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   268
    self assert:( 1.0 asIEEEFloat - 1.0 ) isZero. "/  class == IEEEFloat.
d6af1cf98136 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   269
    self assert:( 1.0 asIEEEFloat - 1.0 asIEEEFloat) isZero. "/ class == IEEEFloat.
d6af1cf98136 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   270
    self assert:( 1.0 asIEEEFloat - 1.0 asShortFloat) isZero. "/ class == IEEEFloat.
d6af1cf98136 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   271
    self assert:( 1.0 asIEEEFloat - 1.0 asLongFloat) isZero. "/ class == IEEEFloat.
d6af1cf98136 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   272
    "/ self assert:( 1.0 asIEEEFloat - 1) class == IEEEFloat.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
    self assert:( 1.0 asIEEEFloat * 1.0 ) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
    self assert:( 1.0 asIEEEFloat * 1.0 asIEEEFloat) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
    self assert:( 1.0 asIEEEFloat * 1.0 asShortFloat) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
    self assert:( 1.0 asIEEEFloat * 1.0 asLongFloat) class == IEEEFloat.
2448
d6af1cf98136 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   278
    "/ self assert:( 1.0 asIEEEFloat * 1) class == IEEEFloat.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
    self assert:( 1.0 asIEEEFloat / 1.0 ) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
    self assert:( 1.0 asIEEEFloat / 1.0 asIEEEFloat) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
    self assert:( 1.0 asIEEEFloat / 1.0 asShortFloat) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
    self assert:( 1.0 asIEEEFloat / 1.0 asLongFloat) class == IEEEFloat.
2448
d6af1cf98136 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   284
    "/ self assert:( 1.0 asIEEEFloat / 1) class == IEEEFloat.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   286
"/    self assert:( 5.0 asIEEEFloat rem: 2.0 ) class == IEEEFloat.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   287
"/    self assert:( 1.0 asIEEEFloat rem: 2.0 asIEEEFloat) class == IEEEFloat.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   288
"/    self assert:( 5.0 asIEEEFloat rem: 2.0 asShortFloat) class == IEEEFloat.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   289
"/    self assert:( 5.0 asIEEEFloat rem: 2.0 asLongFloat) class == IEEEFloat.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   290
"/    "/ self assert:( 5.0 asIEEEFloat rem: 2) class == IEEEFloat.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
     self basicNew test04_Arithmetic
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
test05_Comparing
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
    |convArray check v1 v2 v1b|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
2462
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   300
    self assert:( 0.0 = -0.0).
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   301
    self assert:( 0.0 asIEEEFloat = -0.0 asIEEEFloat).
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   302
    self assert:( 0.0 asIEEEFloat = 0.0).
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   303
    self assert:( 0.0 asIEEEFloat = -0.0).
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   304
    self assert:( -0.0 asIEEEFloat = 0.0).
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   305
    self assert:( -0.0 asIEEEFloat = -0.0).
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   306
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   307
    self assert:( 1.0 asIEEEFloat = 1.0).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   308
    self assert:( 1.0 asIEEEFloat = 1.0 asIEEEFloat).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   309
    self assert:( 1.0 asIEEEFloat = 1.0 asShortFloat).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   310
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   311
    "/ fails currently
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   312
    "/ self assert:( 1.0 asIEEEFloat = 1.0 asLongFloat).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   313
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
    convArray := OrderedCollection new.
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   315
    convArray addAll:#(asInteger asFloat asShortFloat asLongFloat).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
    (Smalltalk at:#LargeFloat) notNil ifTrue:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
        convArray add:#asLargeFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
    (Smalltalk at:#QDouble) notNil ifTrue:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
        convArray add:#asQDouble.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
    check := [:iv1 :iv2|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
        convArray do:[:conv1 |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
            v1 := (iv1 perform:conv1).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
            self assert:( v1 = nil ) not.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
            self assert:( nil = v1 ) not.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
            self assert:( v1 ~= nil ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
            self assert:( nil ~= v1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
            convArray do:[:conv2 |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
                v1b := (iv1 perform:conv2).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
                self assert:( v1 = v1b ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
                self assert:( v1 <= v1b ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
                self assert:( v1 >= v1b ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
                v2 := (iv2 perform:conv2).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
                self assert:( v1 < v2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
                self assert:( v1 <= v2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
                self assert:( v2 >= v1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
                self assert:( v2 > v1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
            ]
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
        ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   350
    check value:2.0 asIEEEFloat value:3.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   351
    check value:0.0 asIEEEFloat value:1.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   352
    check value:-1.0 asIEEEFloat value:0.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   353
    check value:-3.0 asIEEEFloat value:-2.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   354
    check value:-3.0 asIEEEFloat value:3.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   356
    check value:-30.0 asIEEEFloat value:1.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   357
    check value:-1.0 asIEEEFloat value:30.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   359
    
2459
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   360
    self assert:( 2000000.0 asIEEEFloat = 2000000.0 ).
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   361
    self assert:( (IEEEFloat fromInteger:2000000) = 2000000.0 asIEEEFloat ).
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   362
    self assert:( 2000000.0 asIEEEFloat = 2000000 ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   363
    self assert:( 2000000 = 2000000.0 asIEEEFloat ).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   365
    self assert:( 2000000.0 asIEEEFloat <= 200000100000000000000 ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   366
    self assert:( 2000000.0 asIEEEFloat <= 2000000 ).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   368
    self assert:( 2000000 <= 2000000.0 asIEEEFloat ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   369
    self assert:( 2000000 <= 2000000.0 asIEEEFloat ).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
     self basicNew test05_Comparing
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
    "Modified: / 06-05-2019 / 14:11:42 / Claus Gittinger"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
test06_MiscMath
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
    |epsilon|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
    epsilon := 0.000001.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
        sqrt       0.5       0.707107
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
        sqrt       4         2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
        exp        0.5       1.64872
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
        ln         0.5       -0.693147
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
        log10      0.5       -0.30103
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
        sin        0.5      0.479426
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
        cos        0.5      0.877583
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
        tan        0.5      0.546302
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
        arcSin     0.5      0.523599
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
        arcCos     0.5      1.0472
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
        arcTan     0.5      0.463648
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
        sinh       0.5      0.521095
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
        cosh       0.5      1.12763
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
        tanh       0.5      0.462117
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
        arcSinh    0.5      0.481212
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
        arcCosh    1.5      1.24983
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
        arcTanh    0.5      0.549306
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
        sin        0.0      0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
        cos        0.0      1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
        tan        0.0      0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
        sinh       0.0      0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
        cosh       0.0      1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
        tanh       0.0      0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
        sin        1.0      0.841471
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
        cos        1.0      0.540302
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
        tan        1.0      1.55741
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
        sinh       1.0      1.1752
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
        cosh       1.0      1.54308
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
        tanh       1.0      0.761594
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
        sin        3.14159  0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
        cos        3.14159  -1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
        tan        3.14159  0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
        sinh       3.14159  11.5487
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
        cosh       3.14159  11.5919
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
        tanh       3.14159  0.996272
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
        tan        0.785398 1.0         "pi/4  -> should be 1"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
        arcCos     -1.0     3.14159     "should be pi"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
        arcSin     1.0      1.5708      "should be pi/2 (1.5708)"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
        arcTan     1.0      0.785398    "should be pi/4 (.785398)"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
    ) inGroupsOf:3 do:[:op :x :expected|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
        |rslt rsltShortFloat rsltLongFloat rsltLargeFloat rsltQDouble|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
        rslt := x perform:op.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
        rsltShortFloat := x asShortFloat perform:op.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
        rsltLongFloat := x asLongFloat perform:op.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
"/        rsltLargeFloat := arg asLargeFloat perform:op.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
"/        rsltQDouble := x asQDouble perform:op.       
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
        self assert:(rslt class == Float).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
        "/ self assert:(rsltShortFloat class == Float).  "/ ??? not a good test; some return a float
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
        self assert:(rsltLongFloat class == LongFloat).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
"/        self assert:(rsltQDouble class == QDouble).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
        self assert:( rslt - rsltShortFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
        self assert:( rslt - rsltLongFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
"/        self assert:( rslt - rsltQDouble ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
"/        self assert:( rslt - rsltLargeFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
        self assert:( rslt - rslt asShortFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
        self assert:( rslt - rslt asLongFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
"/        self assert:( rslt - rsltQDouble asFloat) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
"/        self assert:( rslt - rslt asLargeFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
    self should:[ -2 arcSin ] raise:DomainError.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
    self should:[ -2 arcCos ] raise:DomainError.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
    self should:[ -1 arcTanh ] raise:DomainError.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
        0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
        2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
        1.57079
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
        self assert:( x sin arcSin - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
        self assert:( x cos arcCos - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
        self assert:( x tan arcTan - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
        -1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
        -0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
        0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
        self assert:( x arcSin sin - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
        self assert:( x arcCos cos - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
        self assert:( x arcTan tan - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
        0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
        2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
        10
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
        self assert:( x cosh arcCosh - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   491
        -10
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
        -2
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
        -1
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
        -0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
        0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
        2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
        10
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
        self assert:( x sinh arcSinh - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
        self assert:( x tanh arcTanh - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
        -0.99
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
        -0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
        0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
        0.99
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
        self assert:( x arcTanh - (( ( (1+x)/(1-x) ) ln ) / 2 ) ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
        -10
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
        -5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
        -2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
        -1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
        2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
        10
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
        self assert:( x arcSinh sinh - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
        2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
        10.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
        self assert:( x arcCosh cosh - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
    self assert:(2.0 raisedTo:2) = 4.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
    self assert:(2 raisedTo:2.0) = 4.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
    self assert:(2.0 raisedTo:2.0) = 4.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
    
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   541
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
     self basicNew test06_MiscMath
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
    "Modified: / 02-07-2017 / 00:51:05 / cg"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   548
test07_Truncation
2462
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   549
    |t check|
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   550
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   551
    t := 0.0 asIEEEFloat coerce:0.
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   552
    self assert:(t isZero).
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   553
    self assert:(t = 0.0 asIEEEFloat).
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   554
    self assert:(t = 0.0).
695bfe3c2283 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2459
diff changeset
   555
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
    check := [:num |
2459
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   558
        |nIEEE|
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   559
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   560
        nIEEE := num asIEEEFloat.
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   561
        self assert:( nIEEE fractionPart ) = num fractionPart asIEEEFloat.
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   562
        nIEEE truncatedAsFloat.
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   563
        self assert:( nIEEE truncatedAsFloat ) = num truncatedAsFloat asIEEEFloat.
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   564
        self assert:( nIEEE truncated ) = num truncated.
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   565
        self assert:( nIEEE fractionPart + nIEEE truncated ) = nIEEE.
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   566
        self assert:( nIEEE fractionPart + nIEEE truncated ) class == nIEEE class.
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   567
        self assert:( nIEEE fractionPart ) = num fractionPart.
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   568
        self assert:( nIEEE truncated ) = num truncated.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   569
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   570
2459
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   571
    check value:0.0 .
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   572
    check value:0.6 .
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   573
    check value:-0.6 .
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   574
    check value:1.6 .
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   575
    check value:-1.6 .
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   576
    check value:1e20 .
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   577
    check value:-1e20 .
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   578
    check value:1e-20 .
8754c5f80a6f #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2458
diff changeset
   579
    check value:-1e-20 .
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
2458
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   581
    self assert:( 1.6 asIEEEFloat ceiling ) = 2.
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   582
    self assert:( 1.6 asIEEEFloat ceilingAsFloat ) = 2.0.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   583
2458
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   584
    self assert:( 1.6 asIEEEFloat floor ) = 1.
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   585
    self assert:( 1.6 asIEEEFloat floorAsFloat ) = 1.0.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   586
2458
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   587
    self assert:( -1.6 asIEEEFloat floor ) = -2.
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   588
    self assert:( -1.6 asIEEEFloat floorAsFloat ) = -2.0.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
2458
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   590
    self assert:( 0.4 asIEEEFloat rounded ) class == SmallInteger.
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   591
    self assert:( 0.4 asIEEEFloat rounded = 0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   592
    self assert:( 0.5 asIEEEFloat rounded = 1 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   593
    self assert:( 0.6 asIEEEFloat rounded = 1 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   594
    self assert:( -0.4 asIEEEFloat rounded = 0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   595
    self assert:( -0.5 asIEEEFloat rounded = -1 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   596
    self assert:( -0.6 asIEEEFloat rounded = -1 ).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   597
2458
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   598
    self assert:( 0.4 asIEEEFloat roundedAsFloat ) class == Float.
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   599
    self assert:( 0.4 asIEEEFloat roundedAsFloat  = 0.0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   600
    self assert:( 0.5 asIEEEFloat roundedAsFloat  = 1.0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   601
    self assert:( 0.6 asIEEEFloat roundedAsFloat  = 1.0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   602
    self assert:( -0.4 asIEEEFloat roundedAsFloat = 0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   603
    self assert:( -0.5 asIEEEFloat roundedAsFloat = -1.0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   604
    self assert:( -0.6 asIEEEFloat roundedAsFloat = -1.0 ).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   605
2458
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   606
    self assert:( 0.4 asIEEEFloat truncated ) class == SmallInteger.
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   607
    self assert:( 0.4 asIEEEFloat truncated = 0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   608
    self assert:( 0.5 asIEEEFloat truncated = 0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   609
    self assert:( 0.6 asIEEEFloat truncated = 0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   610
    self assert:( -0.4 asIEEEFloat truncated = 0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   611
    self assert:( -0.5 asIEEEFloat truncated = 0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   612
    self assert:( -0.6 asIEEEFloat truncated = 0 ).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   613
2458
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   614
    self assert:( 0.4 asIEEEFloat truncatedAsFloat ) class == Float.
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   615
    self assert:( 0.4 asIEEEFloat truncatedAsFloat  = 0.0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   616
    self assert:( 0.5 asIEEEFloat truncatedAsFloat  = 0.0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   617
    self assert:( 0.6 asIEEEFloat truncatedAsFloat  = 0.0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   618
    self assert:( -0.4 asIEEEFloat truncatedAsFloat = 0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   619
    self assert:( -0.5 asIEEEFloat truncatedAsFloat = 0.0 ).
c1adf66c10d4 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 2451
diff changeset
   620
    self assert:( -0.6 asIEEEFloat truncatedAsFloat = 0.0 ).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
     self basicNew test07_Truncation
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
test08_Representation
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
    |noQuadFloats noOctaFloats|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   629
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
    noQuadFloats := UnimplementedFunctionalityError catch:[1.0 asQuadFloat].  
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
    noOctaFloats := UnimplementedFunctionalityError catch:[1.0 asOctaFloat].    
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   633
    self assert:( 1.0 asShortFloat exponentBits = 1.0 asShortFloat asIEEEFloat exponentBits).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   634
    self assert:( 1.0 exponentBits = 1.0 asIEEEFloat exponentBits ).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   636
    self assert:( 0.0 exponent = 0.0 asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   637
    self assert:( 1.0 exponent = 1.0 asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   638
    self assert:( 2.0 exponent = 2.0 asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   639
    self assert:( 3.0 exponent = 3.0 asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   640
    self assert:( 4.0 exponent = 4.0 asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   641
    self assert:( 0.5 exponent = 0.5 asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   642
    self assert:( 0.4 exponent = 0.4 asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   643
    self assert:( 0.25 exponent = 0.25asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   644
    self assert:( 0.125 exponent = 0.125 asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   645
    self assert:( 0.00000011111 exponent = 0.00000011111 asIEEEFloat exponent).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   647
    self assert:( 0.0 asShortFloat exponent = 0.0 asShortFloat asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   648
    self assert:( 1.0 asShortFloat exponent = 1.0 asShortFloat asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   649
    self assert:( 2.0 asShortFloat exponent = 2.0 asShortFloat asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   650
    self assert:( 3.0 asShortFloat exponent = 3.0 asShortFloat asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   651
    self assert:( 4.0 asShortFloat exponent = 4.0 asShortFloat asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   652
    self assert:( 0.5 asShortFloat exponent = 0.5 asShortFloat asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   653
    self assert:( 0.4 asShortFloat exponent = 0.4 asShortFloat asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   654
    self assert:( 0.25 asShortFloat exponent = 0.25 asShortFloat asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   655
    self assert:( 0.125 asShortFloat exponent = 0.125 asShortFloat asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   656
    self assert:( 0.00000011111 asShortFloat exponent = 0.00000011111 asIEEEFloat asShortFloat exponent ).
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   657
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   658
     #( 1.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   659
        2.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   660
        3.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   661
        4.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   662
        12345.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   663
        0.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   664
        -1.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   665
        -2.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   666
        -3.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   667
        -4.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   668
        -12345.0 
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   669
     ) do:[:f  |
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   670
        self assert:( f exponent = f asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   671
        self assert:( f mantissaBits = f asIEEEFloat mantissaBits ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   672
        self assert:( f mantissa = f asIEEEFloat mantissa ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   673
        self assert:( f mantissa * (2 raisedTo:f exponent)) = f.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   674
        self assert:( f asIEEEFloat mantissa * (2 raisedTo:f asIEEEFloat exponent)) = f asIEEEFloat.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
2451
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   676
        self assert:( f asShortFloat exponent = f asShortFloat asIEEEFloat exponent ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   677
        self assert:( f asShortFloat mantissaBits = f asShortFloat asIEEEFloat mantissaBits ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   678
        self assert:( f asShortFloat mantissa = f asShortFloat asIEEEFloat mantissa ).
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   679
        self assert:( f asShortFloat mantissa * (2 raisedTo:f asShortFloat exponent)) = f asShortFloat.
9184c6a9f95c #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 2448
diff changeset
   680
        self assert:( f asShortFloat asIEEEFloat mantissa * (2 raisedTo:f asShortFloat asIEEEFloat exponent)) = f asShortFloat asIEEEFloat.
2443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   681
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   682
        noQuadFloats ifFalse:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
        ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   684
        noOctaFloats ifFalse:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
        ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   686
     ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   688
     self basicNew test08_Representation
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   690
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   691
    "Modified: / 02-08-2011 / 18:34:39 / cg"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   692
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   693
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   694
test09_ComplexRoots
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   695
    |rslt|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   696
    
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   697
    self should:[ -4 sqrt ] raise:ImaginaryResultError.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   699
    rslt := Complex trapImaginary:[ -4 sqrt ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
    self assert:(rslt = 2 i).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   701
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
    rslt := nil.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   703
    Complex trapImaginary:[ rslt := -4 sqrt ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   704
    self assert:(rslt = 2 i).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
    self shouldnt:[ rslt := -8 cbrt ] raise:ImaginaryResultError.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   707
    self assert:(rslt = -2).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
     self basicNew test09_ComplexRoots
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   711
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
    "Created: / 03-07-2017 / 13:51:54 / cg"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   715
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   716
test_11a_pi
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   717
    "/ Machin's Formula for Pi pi / 4  =  4 arctan(1/5) - arctan(1/239)
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   719
    | at1_5 at1_239 pi_4 pi err|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   720
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
    at1_5 := (1.0 / 5) arcTan.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
    at1_239 := (1.0 / 239) arcTan.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
    pi_4 := (at1_5 * 4) - at1_239.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   724
    pi := pi_4 * 4. 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   725
    err := Float pi - pi.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
    self assert:(err < (8 * Float epsilon)).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
test_11b_pi
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
    "/ Salamin-Brent Quadratic Formula for Pi
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   732
    | max_iter a b s m a_new b_new p_old pi err|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   733
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   734
    max_iter := 6.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   735
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
    a := 1.0 asFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
    b := 0.5 asFloat sqrt.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
    s := 0.5 asFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
    m := 1.0 asFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
    pi := 2.0 asFloat * a squared / s.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
    1 to:max_iter do:[:i |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
        m := m * 2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
        a_new := 0.5 * (a+b).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   745
        b_new := a * b.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   746
        s := s - (m * (a_new squared - b_new)).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   747
        a := a_new.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   748
        b := b_new sqrt.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   749
        p_old := pi.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   750
        pi := 2 * a squared / s.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   751
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   752
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   753
    err := Float pi - pi.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   754
    self assert:(err < (8 * Float epsilon)).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   755
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   756
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   757
test_12_e
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   758
    "/ Taylor for e
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   759
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
    | e t n i err|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
    e := 2.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   763
    t := 1.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
    n := 1.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
    i := 0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   766
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   767
    [t > Float epsilon] whileTrue:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   768
        i := i + 1.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   769
        n := n + 1.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   770
        t := t / n.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   771
        e := e + t.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   772
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   773
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   774
    err := Float e - e.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
    self assert:(err < (8 * Float epsilon)).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   776
! !
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   778
!IEEEFloatTest class methodsFor:'documentation'!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   779
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   780
version_CVS
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   781
    ^ '$Header$'
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   782
! !
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   783