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