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