RegressionTests__IEEEFloatTest.st
author Claus Gittinger <cg@exept.de>
Sun, 01 Dec 2019 12:45:23 +0100
changeset 2448 d6af1cf98136
parent 2443 d8841e35d44f
child 2451 9184c6a9f95c
permissions -rw-r--r--
#BUGFIX by exept class: RegressionTests::IEEEFloatTest class definition added: #test00_Precision #test01_Nan #test02_Inf #test03_Conversion #test04_Arithmetic #test05_Comparing #test06_MiscMath #test07_Truncation #test08_Representation #test09_ComplexRoots #test_11a_pi #test_11b_pi #test_12_e class: RegressionTests::IEEEFloatTest class added: #actualPrecisionOf: #version_CVS
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
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
    self assert:( 5.0 asIEEEFloat rem: 2.0 ) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
    self assert:( 1.0 asIEEEFloat rem: 2.0 asIEEEFloat) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
    self assert:( 5.0 asIEEEFloat rem: 2.0 asShortFloat) class == IEEEFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
    self assert:( 5.0 asIEEEFloat rem: 2.0 asLongFloat) class == IEEEFloat.
2448
d6af1cf98136 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 2443
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
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
    convArray := OrderedCollection new.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
    convArray addAll:#(yourself asInteger asFloat asShortFloat asLongFloat).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
    (Smalltalk at:#LargeFloat) notNil ifTrue:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
        convArray add:#asLargeFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
    (Smalltalk at:#QDouble) notNil ifTrue:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
        convArray add:#asQDouble.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
    check := [:iv1 :iv2|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
        convArray do:[:conv1 |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
            v1 := (iv1 perform:conv1).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
            self assert:( v1 = nil ) not.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
            self assert:( nil = v1 ) not.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
            self assert:( v1 ~= nil ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
            self assert:( nil ~= v1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
            convArray do:[:conv2 |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
                v1b := (iv1 perform:conv2).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
                self assert:( v1 = v1b ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
                self assert:( v1 <= v1b ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
                self assert:( v1 >= v1b ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
                v2 := (iv2 perform:conv2).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
                self assert:( v1 < v2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
                self assert:( v1 <= v2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
                self assert:( v2 >= v1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
                self assert:( v2 > v1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
            ]
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
        ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
    check value:2 value:3.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
    check value:0 value:1.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
    check value:-1 value:0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
    check value:-3 value:-2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
    check value:-3 value:3.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
    check value:-30 value:1.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
    check value:-1 value:30.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
    "/ showing that float precision is limited...
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
    
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
    "/ test fails when stc code, jit code works
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
    false "(Helper 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
        isStcCompiledMethod:#'test05_Comparing'
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
        in:self)" ifTrue:[ 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
            "/ stc-compiled code handles not slightly differently
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
            "/ listed compares will fail
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
            'FloatTest >> test05_Comparing: test with 200000000000000000000 or similiar are skipped due would fail when stc code' infoPrintCR.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
        ] ifFalse:[    
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
            self assert:( 200000000000000000000.0 = 200000000000000000001.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
            self assert:( 200000000000000000000.0 = 200000000000000000001 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
            self assert:( 200000000000000000000.0 = 200000000000000000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
            self assert:( 200000000000000000000.0 asLongFloat = 200000000000000000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
            self assert:( 200000000000000000000 = 200000000000000000000.0).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
            self assert:( 200000000000000000000 = 200000000000000000000.0 asLongFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
            self assert:( 200000000000000000000.0 < 200000100000000000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
            self assert:( 200000000000000000000.0 asLongFloat < 200000000000100000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
            self assert:( 200000000000000000000.0 asShortFloat < 200001000000000000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
            self assert:( 200000000000000000000 < 200001000000000000000.0).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
            self assert:( 200000000000000000000 < 200001000000000000000.0 asLongFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
            self assert:( 200000000000000000000 < 200001000000000000000.0 asShortFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
            self assert:( 200000000000000000000.0 <= 200000100000000000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
            self assert:( 200000000000000000000.0 <= 200000000000000000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
            self assert:( 200000000000000000000.0 asLongFloat <= 200000000000000000001 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
            self assert:( 200000000000000000000.0 asLongFloat <= 200000000000000000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
            self assert:( 200000000000000000000 <= 200001000000000000000.0).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
            self assert:( 200000000000000000000 <= 200000000000000000000.0).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
            self assert:( 200000000000000000000 <= 200001000000000000000.0 asLongFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
            self assert:( 200000000000000000000 <= 200000000000000000000.0 asLongFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
        ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
    self assert:( 2000000.0 asShortFloat = 2000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
    self assert:( 2000000 = 2000000.0 asShortFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
    self assert:( 2000000.0 asShortFloat <= 200000100000000000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
    self assert:( 2000000.0 asShortFloat <= 2000000 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
    self assert:( 2000000 <= 2000000.0 asShortFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
    self assert:( 2000000 <= 2000000.0 asShortFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
     self basicNew test05_Comparing
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
    "Modified: / 06-05-2019 / 14:11:42 / Claus Gittinger"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
test06_MiscMath
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
    |epsilon|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
    epsilon := 0.000001.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
        sqrt       0.5       0.707107
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
        sqrt       4         2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
        exp        0.5       1.64872
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
        ln         0.5       -0.693147
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
        log10      0.5       -0.30103
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
        sin        0.5      0.479426
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
        cos        0.5      0.877583
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
        tan        0.5      0.546302
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
        arcSin     0.5      0.523599
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
        arcCos     0.5      1.0472
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
        arcTan     0.5      0.463648
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
        sinh       0.5      0.521095
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
        cosh       0.5      1.12763
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
        tanh       0.5      0.462117
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
        arcSinh    0.5      0.481212
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
        arcCosh    1.5      1.24983
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
        arcTanh    0.5      0.549306
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
        sin        0.0      0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
        cos        0.0      1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
        tan        0.0      0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
        sinh       0.0      0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
        cosh       0.0      1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
        tanh       0.0      0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
        sin        1.0      0.841471
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
        cos        1.0      0.540302
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
        tan        1.0      1.55741
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
        sinh       1.0      1.1752
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
        cosh       1.0      1.54308
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
        tanh       1.0      0.761594
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
        sin        3.14159  0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
        cos        3.14159  -1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
        tan        3.14159  0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
        sinh       3.14159  11.5487
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
        cosh       3.14159  11.5919
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
        tanh       3.14159  0.996272
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
        tan        0.785398 1.0         "pi/4  -> should be 1"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
        arcCos     -1.0     3.14159     "should be pi"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
        arcSin     1.0      1.5708      "should be pi/2 (1.5708)"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
        arcTan     1.0      0.785398    "should be pi/4 (.785398)"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
    ) inGroupsOf:3 do:[:op :x :expected|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
        |rslt rsltShortFloat rsltLongFloat rsltLargeFloat rsltQDouble|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
        rslt := x perform:op.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
        rsltShortFloat := x asShortFloat perform:op.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
        rsltLongFloat := x asLongFloat perform:op.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
"/        rsltLargeFloat := arg asLargeFloat perform:op.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
"/        rsltQDouble := x asQDouble perform:op.       
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
        self assert:(rslt class == Float).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
        "/ self assert:(rsltShortFloat class == Float).  "/ ??? not a good test; some return a float
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
        self assert:(rsltLongFloat class == LongFloat).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
"/        self assert:(rsltQDouble class == QDouble).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
        self assert:( rslt - rsltShortFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
        self assert:( rslt - rsltLongFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
"/        self assert:( rslt - rsltQDouble ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
"/        self assert:( rslt - rsltLargeFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
        self assert:( rslt - rslt asShortFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
        self assert:( rslt - rslt asLongFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
"/        self assert:( rslt - rsltQDouble asFloat) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
"/        self assert:( rslt - rslt asLargeFloat ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
    self should:[ -2 arcSin ] raise:DomainError.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
    self should:[ -2 arcCos ] raise:DomainError.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
    self should:[ -1 arcTanh ] raise:DomainError.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
        0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
        2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
        1.57079
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
        self assert:( x sin arcSin - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
        self assert:( x cos arcCos - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
        self assert:( x tan arcTan - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
        -1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
        -0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   491
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
        0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
        self assert:( x arcSin sin - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
        self assert:( x arcCos cos - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
        self assert:( x arcTan tan - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
        0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
        2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
        10
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
        self assert:( x cosh arcCosh - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
        -10
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
        -2
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
        -1
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
        -0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
        0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
        2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
        10
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
        self assert:( x sinh arcSinh - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
        self assert:( x tanh arcTanh - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
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
        -0.99
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
        -0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
        0.5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
        0.99
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
        self assert:( x arcTanh - (( ( (1+x)/(1-x) ) ln ) / 2 ) ) < epsilon.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
        -10
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
        -5
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
        -2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
        -1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
        0.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   541
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
        2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
        10
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
        self assert:( x arcSinh sinh - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   548
    #(
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
        1.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
        2.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
        10.0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
     ) do:[:x |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
        self assert:( x arcCosh cosh - x < epsilon).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
    self assert:(2.0 raisedTo:2) = 4.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
    self assert:(2 raisedTo:2.0) = 4.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
    self assert:(2.0 raisedTo:2.0) = 4.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
    
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
     self basicNew test06_MiscMath
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   562
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
    "Modified: / 02-07-2017 / 00:51:05 / cg"
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
test07_Truncation
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
    |check|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   569
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   570
    check := [:num |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   571
        self assert:( num fractionPart + num truncated ) = num.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   572
        self assert:( num fractionPart + num truncated ) class == num class.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   573
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   574
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   575
    check value:1.6.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   576
    check value:-1.6.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   577
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
    check value:1.6 asShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
    check value:-1.6 asShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   581
    check value:1.6 asLongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   582
    check value:-1.6 asLongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   583
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   584
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   585
    self assert:( 1.6 ceiling ) = 2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   586
    self assert:( 1.6 asShortFloat ceiling ) = 2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   587
    self assert:( 1.6 asLongFloat ceiling ) = 2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   588
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
    self assert:( 1.6 ceilingAsFloat ) = 2.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   590
    self assert:( 1.6 ceilingAsFloat ) class == Float.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   591
    self assert:( 1.6 asShortFloat ceilingAsFloat ) = 2.0 asShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   592
    self assert:( 1.6 asShortFloat ceilingAsFloat ) class == ShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   593
    self assert:( 1.6 asLongFloat ceilingAsFloat ) = 2.0 asLongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   594
    self assert:( 1.6 asLongFloat ceilingAsFloat ) class == LongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   596
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   597
    self assert:( 1.6 floor ) = 1.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   598
    self assert:( 1.6 asShortFloat floor ) = 1.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
    self assert:( 1.6 asLongFloat floor ) = 1.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   600
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   601
    self assert:( 1.6 floorAsFloat ) = 1.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   602
    self assert:( 1.6 floorAsFloat ) class == Float.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   603
    self assert:( 1.6 asShortFloat floorAsFloat ) = 1.0 asShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
    self assert:( 1.6 asShortFloat floorAsFloat ) class == ShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   605
    self assert:( 1.6 asLongFloat floorAsFloat ) = 1.0 asLongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   606
    self assert:( 1.6 asLongFloat floorAsFloat ) class == LongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
    self assert:( -1.6 floor ) = -2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   609
    self assert:( -1.6 asShortFloat floor ) = -2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   610
    self assert:( -1.6 asLongFloat floor ) = -2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
    self assert:( -1.6 floorAsFloat ) = -2.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   613
    self assert:( -1.6 floorAsFloat ) class == Float.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
    self assert:( -1.6 asShortFloat floorAsFloat ) = -2.0 asShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
    self assert:( -1.6 asShortFloat floorAsFloat ) class == ShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
    self assert:( -1.6 asLongFloat floorAsFloat ) = -2.0 asLongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   617
    self assert:( -1.6 asLongFloat floorAsFloat ) class == LongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   619
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   620
    self assert:( 0.4 rounded ) class == SmallInteger.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
    self assert:( 0.4 rounded = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
    self assert:( 0.5 rounded = 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
    self assert:( 0.6 rounded = 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
    self assert:( -0.4 rounded = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
    self assert:( -0.5 rounded = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
    self assert:( -0.6 rounded = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
    self assert:( 0.4 roundedAsFloat ) class == Float.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   629
    self assert:( 0.4 roundedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
    self assert:( 0.5 roundedAsFloat  = 1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
    self assert:( 0.6 roundedAsFloat  = 1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
    self assert:( -0.4 roundedAsFloat = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   633
    self assert:( -0.5 roundedAsFloat = -1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   634
    self assert:( -0.6 roundedAsFloat = -1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   636
    self assert:( 0.4 asShortFloat rounded ) class == SmallInteger.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   637
    self assert:( 0.4 asShortFloat rounded = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   638
    self assert:( 0.5 asShortFloat rounded = 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   639
    self assert:( 0.6 asShortFloat rounded = 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   640
    self assert:( -0.4 asShortFloat rounded = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   641
    self assert:( -0.5 asShortFloat rounded = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   642
    self assert:( -0.6 asShortFloat rounded = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   643
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   644
    self assert:( 0.4 asShortFloat roundedAsFloat ) class == ShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   645
    self assert:( 0.4 asShortFloat roundedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
    self assert:( 0.5 asShortFloat roundedAsFloat  = 1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
    self assert:( 0.6 asShortFloat roundedAsFloat  = 1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
    self assert:( -0.4 asShortFloat roundedAsFloat = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
    self assert:( -0.5 asShortFloat roundedAsFloat = -1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
    self assert:( -0.6 asShortFloat roundedAsFloat = -1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
    self assert:( 0.4 asLongFloat rounded ) class == SmallInteger.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
    self assert:( 0.4 asLongFloat rounded = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   654
    self assert:( 0.5 asLongFloat rounded = 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   655
    self assert:( 0.6 asLongFloat rounded = 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   656
    self assert:( -0.4 asLongFloat rounded = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   657
    self assert:( -0.5 asLongFloat rounded = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
    self assert:( -0.6 asLongFloat rounded = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
    self assert:( 0.4 asLongFloat roundedAsFloat ) class == LongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   661
    self assert:( 0.4 asLongFloat roundedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   662
    self assert:( 0.5 asLongFloat roundedAsFloat  = 1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   663
    self assert:( 0.6 asLongFloat roundedAsFloat  = 1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   664
    self assert:( -0.4 asLongFloat roundedAsFloat = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   665
    self assert:( -0.5 asLongFloat roundedAsFloat = -1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   666
    self assert:( -0.6 asLongFloat roundedAsFloat = -1.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   668
    self assert:( 0.4 truncated ) class == SmallInteger.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   669
    self assert:( 0.4 truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   670
    self assert:( 0.5 truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   671
    self assert:( 0.6 truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   672
    self assert:( -0.4 truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   673
    self assert:( -0.5 truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   674
    self assert:( -0.6 truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   676
    self assert:( 0.4 truncatedAsFloat ) class == Float.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   677
    self assert:( 0.4 truncatedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   678
    self assert:( 0.5 truncatedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   679
    self assert:( 0.6 truncatedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
    self assert:( -0.4 truncatedAsFloat = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   681
    self assert:( -0.5 truncatedAsFloat = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   682
    self assert:( -0.6 truncatedAsFloat = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   684
    self assert:( 0.4 asShortFloat truncated ) class == SmallInteger.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
    self assert:( 0.4 asShortFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   686
    self assert:( 0.5 asShortFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
    self assert:( 0.6 asShortFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   688
    self assert:( -0.4 asShortFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
    self assert:( -0.5 asShortFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   690
    self assert:( -0.6 asShortFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   691
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   692
    self assert:( 0.4 asShortFloat truncatedAsFloat ) class == ShortFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   693
    self assert:( 0.4 asShortFloat truncatedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   694
    self assert:( 0.5 asShortFloat truncatedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   695
    self assert:( 0.6 asShortFloat truncatedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   696
    self assert:( -0.4 asShortFloat truncatedAsFloat = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   697
    self assert:( -0.5 asShortFloat truncatedAsFloat = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
    self assert:( -0.6 asShortFloat truncatedAsFloat = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   699
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
    self assert:( 0.4 asLongFloat truncated ) class == SmallInteger.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   701
    self assert:( 0.4 asLongFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
    self assert:( 0.5 asLongFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   703
    self assert:( 0.6 asLongFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   704
    self assert:( -0.4 asLongFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
    self assert:( -0.5 asLongFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
    self assert:( -0.6 asLongFloat truncated = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   707
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
    self assert:( 0.4 asLongFloat truncatedAsFloat ) class == LongFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
    self assert:( 0.4 asLongFloat truncatedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
    self assert:( 0.5 asLongFloat truncatedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   711
    self assert:( 0.6 asLongFloat truncatedAsFloat  = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
    self assert:( -0.4 asLongFloat truncatedAsFloat = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
    self assert:( -0.5 asLongFloat truncatedAsFloat = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
    self assert:( -0.6 asLongFloat truncatedAsFloat = 0.0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   715
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   716
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   717
     self basicNew test07_Truncation
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   719
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   720
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
test08_Representation
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
    |noQuadFloats noOctaFloats|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   724
    noQuadFloats := UnimplementedFunctionalityError catch:[1.0 asQuadFloat].  
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   725
    noOctaFloats := UnimplementedFunctionalityError catch:[1.0 asOctaFloat].    
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
    self assert: (Float unity class == Float).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
    self assert: (ShortFloat unity class == ShortFloat).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
    self assert: (LongFloat unity class == LongFloat).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
    self assert: (Float unity = 1.0).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   732
    self assert: (ShortFloat unity = 1.0).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   733
    self assert: (LongFloat unity = 1.0).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   734
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   735
    self assert: (Float zero class == Float).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
    self assert: (ShortFloat zero class == ShortFloat).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
    self assert: (LongFloat zero class == LongFloat).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
    self assert: (Float zero = 0.0).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
    self assert: (ShortFloat zero = 0.0).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
    self assert: (LongFloat zero = 0.0).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
    self assert:( LongFloat unity = 1 asLongFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
    self assert:( ShortFloat unity = 1 asShortFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   745
    self assert:( Float unity = 1 asFloat ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   746
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   747
    self assert:( 0.0 exponent = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   748
    self assert:( 1.0 exponent = 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   749
    self assert:( 2.0 exponent = 2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   750
    self assert:( 3.0 exponent = 2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   751
    self assert:( 4.0 exponent = 3 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   752
    self assert:( 0.5 exponent = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   753
    self assert:( 0.4 exponent = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   754
    self assert:( 0.25 exponent = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   755
    self assert:( 0.125 exponent = -2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   756
    self assert:( 0.00000011111 exponent = -23 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   757
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   758
    self assert:( 0.0 asShortFloat exponent = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   759
    self assert:( 1.0 asShortFloat exponent = 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
    self assert:( 2.0 asShortFloat exponent = 2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
    self assert:( 3.0 asShortFloat exponent = 2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
    self assert:( 4.0 asShortFloat exponent = 3 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   763
    self assert:( 0.5 asShortFloat exponent = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
    self assert:( 0.4 asShortFloat exponent = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
    self assert:( 0.25 asShortFloat exponent = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   766
    self assert:( 0.125 asShortFloat exponent = -2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   767
    self assert:( 0.00000011111 asShortFloat exponent = -23 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   768
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   769
    self assert:( 0.0 asLongFloat exponent = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   770
    self assert:( 1.0 asLongFloat exponent = 1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   771
    self assert:( 2.0 asLongFloat exponent = 2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   772
    self assert:( 3.0 asLongFloat exponent = 2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   773
    self assert:( 4.0 asLongFloat exponent = 3 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   774
    self assert:( 0.5 asLongFloat exponent = 0 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
    self assert:( 0.4 asLongFloat exponent = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   776
    self assert:( 0.25 asLongFloat exponent = -1 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
    self assert:( 0.125 asLongFloat exponent = -2 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   778
    self assert:( 0.00000011111 asLongFloat exponent = -23 ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   779
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   780
     #( 1.0 1
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   781
        2.0 2
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   782
        3.0 3
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   783
        4.0 4
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   784
        12345.0 12345
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
        0.0 0
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
        -1.0 -1
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
        -2.0 -2
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
        -3.0 -3
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
        -4.0 -4
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   790
        -12345.0 -12345
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   791
     ) pairWiseDo:[:f :i |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
        self assert:( f exponent = i exponent ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
        self assert:( f mantissa = i mantissa ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
        self assert:( f mantissa * (2 raisedTo:f exponent))= f.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
        self assert:( i mantissa * (2 raisedTo:i exponent)) = i.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   797
        self assert:( f exponent = f asShortFloat exponent ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   798
        self assert:( f exponent = f asLongFloat exponent ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   799
        self assert:( f exponent = f asQDouble exponent ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   800
        self assert:( f asShortFloat mantissa * (2 raisedTo:f asShortFloat exponent))= f.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   801
        self assert:( f asLongFloat mantissa * (2 raisedTo:f asLongFloat exponent))= f.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   802
        self assert:( f asQDouble mantissa * (2 raisedTo:f asQDouble exponent))= f.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   803
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   804
        noQuadFloats ifFalse:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   805
            self assert:( f exponent = f asQuadFloat exponent ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
            self assert:( f asQuadFloat mantissa * (2 raisedTo:f asQuadFloat exponent))= f.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   807
        ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   808
        noOctaFloats ifFalse:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
            self assert:( f exponent = f asOctaFloat exponent ).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
            self assert:( f asOctaFloat mantissa * (2 raisedTo:f asOctaFloat exponent))= f.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
        ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
     ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   814
     self basicNew test08_Representation
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
    "Modified: / 02-08-2011 / 18:34:39 / cg"
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
test09_ComplexRoots
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
    |rslt|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
    
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
    self should:[ -4 sqrt ] raise:ImaginaryResultError.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
    rslt := Complex trapImaginary:[ -4 sqrt ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   826
    self assert:(rslt = 2 i).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   827
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   828
    rslt := nil.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   829
    Complex trapImaginary:[ rslt := -4 sqrt ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
    self assert:(rslt = 2 i).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
    self shouldnt:[ rslt := -8 cbrt ] raise:ImaginaryResultError.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   833
    self assert:(rslt = -2).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   834
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   835
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
     self basicNew test09_ComplexRoots
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
    "
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
    "Created: / 03-07-2017 / 13:51:54 / cg"
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
test_11a_pi
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   843
    "/ 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
   844
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   845
    | at1_5 at1_239 pi_4 pi err|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   846
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
    at1_5 := (1.0 / 5) arcTan.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
    at1_239 := (1.0 / 239) arcTan.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
    pi_4 := (at1_5 * 4) - at1_239.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   850
    pi := pi_4 * 4. 
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
    err := Float pi - pi.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
    self assert:(err < (8 * Float epsilon)).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   853
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   854
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   855
test_11b_pi
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   856
    "/ Salamin-Brent Quadratic Formula for Pi
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   858
    | 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
   859
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
    max_iter := 6.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   862
    a := 1.0 asFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
    b := 0.5 asFloat sqrt.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   864
    s := 0.5 asFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   865
    m := 1.0 asFloat.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
    pi := 2.0 asFloat * a squared / s.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
    1 to:max_iter do:[:i |
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   869
        m := m * 2.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   870
        a_new := 0.5 * (a+b).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   871
        b_new := a * b.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   872
        s := s - (m * (a_new squared - b_new)).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   873
        a := a_new.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   874
        b := b_new sqrt.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   875
        p_old := pi.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
        pi := 2 * a squared / s.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   878
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   879
    err := Float pi - pi.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   880
    self assert:(err < (8 * Float epsilon)).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   881
!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   882
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   883
test_12_e
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   884
    "/ Taylor for e
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   885
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   886
    | e t n i err|
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   887
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   888
    e := 2.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   889
    t := 1.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   890
    n := 1.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   891
    i := 0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   892
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   893
    [t > Float epsilon] whileTrue:[
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   894
        i := i + 1.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   895
        n := n + 1.0.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   896
        t := t / n.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   897
        e := e + t.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   898
    ].
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   899
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   900
    err := Float e - e.
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   901
    self assert:(err < (8 * Float epsilon)).
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   902
! !
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   903
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   904
!IEEEFloatTest class methodsFor:'documentation'!
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   905
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   906
version_CVS
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   907
    ^ '$Header$'
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   908
! !
d8841e35d44f initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   909