RegressionTests__LargeFloatTest.st
author Claus Gittinger <cg@exept.de>
Tue, 28 May 2019 08:32:36 +0200
changeset 2248 55f846f2839b
parent 1828 44017f139f51
child 2249 098f9577859b
permissions -rw-r--r--
#QUALITY by cg class: RegressionTests::LargeFloatTest class definition added:82 methods class: RegressionTests::LargeFloatTest class added: #documentation #version #version_CVS
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1828
44017f139f51 #BUGFIX by sr
sr
parents: 1775
diff changeset
     1
"{ Encoding: utf8 }"
44017f139f51 #BUGFIX by sr
sr
parents: 1775
diff changeset
     2
204
7a02eaf7f06b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"{ NameSpace: RegressionTests }"
7a02eaf7f06b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
7a02eaf7f06b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
TestCase subclass:#LargeFloatTest
2248
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
     6
	instanceVariableNames:'zero one two half minusOne minusTwo huge'
204
7a02eaf7f06b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	classVariableNames:''
7a02eaf7f06b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	poolDictionaries:''
1070
3a47933aea21 category
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
     9
	category:'tests-Regression-Numbers'
204
7a02eaf7f06b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!
7a02eaf7f06b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
2248
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    12
LargeFloatTest comment:'Test to check FloatingPoint numbers with arbitrary precision'
1775
68746cad01d9 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1752
diff changeset
    13
!
68746cad01d9 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1752
diff changeset
    14
204
7a02eaf7f06b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
!LargeFloatTest class methodsFor:'documentation'!
7a02eaf7f06b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
2248
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    17
documentation
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    18
"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    19
    documentation to be added.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    20
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    21
    [author:]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    22
        Claus Gittinger
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    23
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    24
    [instance variables:]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    25
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    26
    [class variables:]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    27
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    28
    [see also:]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    29
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    30
"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    31
! !
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    32
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    33
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    34
!LargeFloatTest methodsFor:'private'!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    35
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    36
checkDoublePrecision: y forFunction: func precision: n
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    37
	"Check that doubling the precision, then rounding would lead to the same result"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    38
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    39
	| anLargeFloat singlePrecisionResult |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    40
	anLargeFloat _ y asLargeFloatPrecision: n.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    41
	singlePrecisionResult _ anLargeFloat perform: func.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    42
	self checkThatEvaluatingFunction: func toDoublePrecisionOf: anLargeFloat equals: singlePrecisionResult.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    43
	^singlePrecisionResult
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    44
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    45
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    46
checkDoublePrecisionSerie: serie forFunction: func 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    47
	^self checkDoublePrecisionSerie: serie forFunction: func precision: Float precision
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    48
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    49
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    50
checkDoublePrecisionSerie: serie forFunction: func precision: n
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    51
	serie do: [:y | self checkDoublePrecision: y forFunction: func precision: n]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    52
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    53
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    54
checkDoublePrecisionSerieVsFloat: serie forFunction: func 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    55
	^serie reject: [:y |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    56
		| farb |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    57
		farb _ self checkDoublePrecision: y forFunction: func precision: Float precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    58
		[(y asFloat perform: func) = farb] on: ZeroDivide do: [false]]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    59
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    60
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    61
checkThatEvaluatingFunction: func toDoublePrecisionOf: anLargeFloat equals: singlePrecisionResult
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    62
	"Check that doubling the precision, then rounding would lead to the same result"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    63
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    64
	| n doublePrecision doublePrecisionResult lowBits |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    65
	n _ anLargeFloat precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    66
	doublePrecision _ anLargeFloat asLargeFloatPrecision: n * 2.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    67
	doublePrecisionResult _ doublePrecision perform: func.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    68
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    69
	"Note: the test must be guarded against double rounding error condition.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    70
	For example, suppose the single precision is 4 bits, double precision 8 bits.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    71
	If exact result is 1.001 | 0111 | 1001...
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    72
	Then the nearest double is rounded to upper 1.001 | 1000
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    73
	Then the nearest single to the double is rounded to upper 1.010
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    74
	But the nearest single to the exact result should have been 1.001
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    75
	To avoid this, we have to check if the second rounding is an exact tie"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    76
	doublePrecisionResult normalize.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    77
	lowBits _ doublePrecisionResult mantissa bitAnd: 1<<n-1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    78
	lowBits = (1<<(n-1))
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    79
		ifTrue:
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    80
			["double precision is ambiguous - retry with quadruple..."
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    81
			^self checkThatEvaluatingFunction: func toQuadruplePrecisionOf: anLargeFloat equals: singlePrecisionResult].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    82
	self assert: ((doublePrecisionResult asLargeFloatPrecision: n)- singlePrecisionResult) isZero
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    83
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    84
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    85
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    86
checkThatEvaluatingFunction: func toQuadruplePrecisionOf: anLargeFloat equals: singlePrecisionResult
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    87
	"Check that quadrupling the precision, then rounding would lead to the same result"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    88
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    89
	| n quadruplePrecision quadruplePrecisionResult lowBits |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    90
	n _ anLargeFloat precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    91
	quadruplePrecision _ anLargeFloat asLargeFloatPrecision: n * 4.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    92
	quadruplePrecisionResult _ quadruplePrecision perform: func.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    93
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    94
	"Guard against double rounding error condition (exact tie)"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    95
	quadruplePrecisionResult normalize.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    96
	lowBits _ quadruplePrecisionResult mantissa bitAnd: 1<<(3*n)-1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    97
	lowBits = (1<<(3*n-1))
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    98
		ifTrue:
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
    99
			["quadruple precision is ambiguous - give up..."
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   100
			^self].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   101
	self assert: ((quadruplePrecisionResult asLargeFloatPrecision: n)- singlePrecisionResult) isZero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   102
! !
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   103
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   104
!LargeFloatTest methodsFor:'setup'!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   105
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   106
setUp
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   107
        zero := 0 asLargeFloatPrecision: 53.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   108
        one := 1 asLargeFloatPrecision: 53.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   109
        two := 2 asLargeFloatPrecision: 53.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   110
        half := (1/2) asLargeFloatPrecision: 53.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   111
        minusOne := -1 asLargeFloatPrecision: 53.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   112
        minusTwo := -2 asLargeFloatPrecision: 53.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   113
        huge := (10 raisedTo: 100) asLargeFloatPrecision: 53.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   114
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   115
    "Modified (format): / 27-05-2019 / 08:25:42 / Claus Gittinger"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   116
! !
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   117
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   118
!LargeFloatTest methodsFor:'testing-arithmetic'!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   119
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   120
testDivide
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   121
        | serie |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   122
        serie := {1. 2. 3. 5. 6. 7. 9. 10. 11. 12. 19. 243. 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   123
                 10 raisedTo: Float precision + 1. 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   124
                 Float precision factorial. 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   125
                 Float pi.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   126
                }.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   127
        serie do: [:num |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   128
                | nf na |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   129
                nf := num asFloat.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   130
                na := num asLargeFloatPrecision: Float precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   131
                serie do:[:den |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   132
                        | df da ff fa |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   133
                        df := den asFloat.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   134
                        da := den asLargeFloatPrecision: Float precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   135
                        ff := nf / df.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   136
                        fa := na / da.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   137
                        self assert: ff = fa]].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   138
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   139
    "Modified (format): / 27-05-2019 / 10:13:11 / Claus Gittinger"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   140
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   141
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   142
testIEEEArithmeticVersusFloat
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   143
	| floats ops ref new |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   144
	floats _ #(1.0 2.0 3.0 5.0 10.0 2r1.0e52 2r1.0e53 2r1.0e54 0.5 0.25 2r1.0e-52 2r1.0e-53 2r1.0e-54 1.0e60 0.1 1.1e-30 1.0e-60) copyWith: Float pi.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   145
	ops _ #(#+ #- #* #/ #= #< #> ).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   146
	ops
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   147
		do: [:op | floats
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   148
				do: [:f1 | floats
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   149
						do: [:f2 | 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   150
							ref _ f1 perform: op with: f2.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   151
							new _ (f1 asLargeFloatPrecision: 53)
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   152
										perform: op
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   153
										with: (f2 asLargeFloatPrecision: 53).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   154
							self assert: new = ref]]]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   155
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   156
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   157
testIEEEArithmeticVersusIntegerAndFraction
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   158
	"check that results are the same as IEEE 754 accelerated hardware
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   159
	WARNING: this cannot be the case for denormalized numbers (gradual underflow)
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   160
	because our exponent is unlimited"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   161
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   162
	| floats ops ref new intAndFractions |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   163
	floats _ #(1.0e0 2.0e0 3.0e0 5.0e0 10.0e0) 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   164
				, (#(52 53 54 -52 -53 -54) collect: [:e | 1.0e0 timesTwoPower: e]) 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   165
					, #(0.5e0 0.25e0 1.0e60 0.1e0 1.1e-30 1.0e-60) copyWith: Float pi.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   166
	intAndFractions _ #(1 3 5 10 12345678901234567890 -1 -22 -3) copyWith: 7/9.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   167
	intAndFractions _ intAndFractions , (intAndFractions collect: [:e | e reciprocal]).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   168
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   169
	ops _ 1/10 = 0.1
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   170
		ifTrue: [#(#+ #- #* #/)]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   171
		ifFalse: [#(#+ #- #* #/ #= #< #>)]. "BEWARE: LargeFloat compare exactly, Float don't, unless http://bugs.squeak.org/view.php?id=3374"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   172
	ops do: 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   173
			[:op | 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   174
			floats do: 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   175
					[:f1 | 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   176
					intAndFractions do: 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   177
							[:f2 | 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   178
							ref _ f1 perform: op with: f2 asFloat.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   179
							new _ (f1 asLargeFloatPrecision: 53) perform: op
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   180
										with: (f2 asLargeFloatPrecision: 53).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   181
							self assert: new = ref.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   182
							new _ f1 perform: op
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   183
										with: (f2 asLargeFloatPrecision: 53).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   184
							self assert: new = ref.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   185
							
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   186
							ref _ f1 perform: op with: f2.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   187
							new _ (f1 asLargeFloatPrecision: 53) perform: op
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   188
										with: f2.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   189
							self assert: new = ref.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   190
							
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   191
							ref _ f2 asFloat perform: op with: f1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   192
							new _ (f2 asLargeFloatPrecision: 53) perform: op
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   193
										with: (f1 asLargeFloatPrecision: 53).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   194
							self assert: new = ref.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   195
							new _ (f2 asLargeFloatPrecision: 53) perform: op with: f1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   196
							self assert: new = ref.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   197
							
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   198
							ref _ f2 perform: op with: f1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   199
							new _ f2 perform: op
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   200
										with: (f1 asLargeFloatPrecision: 53).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   201
							self assert: new = ref]]]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   202
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   203
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   204
testMultiply
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   205
	self assert: zero * zero = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   206
	self assert: zero * minusOne = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   207
	self assert: huge * zero = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   208
	self assert: one * zero = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   209
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   210
	self assert: one * two = two.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   211
	self assert: minusOne * one = minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   212
	self assert: minusOne * minusTwo = two.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   213
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   214
	self assert: half * two = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   215
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   216
	"check rounding"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   217
	self assert: huge * one = huge.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   218
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   219
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   220
testNegated
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   221
	self assert: zero negated = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   222
	self assert: one negated = minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   223
	self assert: minusTwo negated = two.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   224
	self assert: huge negated negated = huge.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   225
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   226
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   227
testPi
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   228
	"check computation of pi"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   229
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   230
	self assert: (1 asLargeFloatPrecision: 53) pi = Float pi.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   231
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   232
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   233
testRaisedToNegativeInteger
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   234
	| n |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   235
	n _ 11.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   236
	1 to: 1<<n-1 do: [:i |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   237
		self assert: ((i asLargeFloatPrecision: n) raisedToInteger: -49)
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   238
			equals: ((i raisedToInteger: -49) asLargeFloatPrecision: n) ].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   239
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   240
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   241
testRaisedToPositiveInteger
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   242
	| n |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   243
	n _ 11.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   244
	1 to: 1<<n-1 do: [:i |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   245
		self assert: ((i asLargeFloatPrecision: n) raisedToInteger: 49)
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   246
			equals: ((i raisedToInteger: 49) asLargeFloatPrecision: n) ].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   247
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   248
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   249
testReciprocal
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   250
	| b |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   251
	b _ 1 << (Float precision - 1).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   252
	1 to: 10000 do: [:i |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   253
		| a |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   254
		a _ i asLargeFloatPrecision: Float precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   255
		self assert: a reciprocal = i asFloat reciprocal.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   256
		self assert: (a+b) reciprocal = (i+b) asFloat reciprocal.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   257
		self assert: a negated reciprocal = i asFloat negated reciprocal.]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   258
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   259
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   260
testRoundToNearestEven
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   261
	"Check that IEEE default rounding mode is honoured,
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   262
	that is rounding to nearest even"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   263
		
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   264
	self assert: ((one timesTwoPower: 52)+(0+(1/4))) asTrueFraction = ((1 bitShift: 52)+0).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   265
	self assert: ((one timesTwoPower: 52)+(0+(1/2))) asTrueFraction = ((1 bitShift: 52)+0).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   266
	self assert: ((one timesTwoPower: 52)+(0+(3/4))) asTrueFraction = ((1 bitShift: 52)+1).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   267
	self assert: ((one timesTwoPower: 52)+(1+(1/4))) asTrueFraction = ((1 bitShift: 52)+1).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   268
	self assert: ((one timesTwoPower: 52)+(1+(1/2))) asTrueFraction = ((1 bitShift: 52)+2).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   269
	self assert: ((one timesTwoPower: 52)+(1+(3/4))) asTrueFraction = ((1 bitShift: 52)+2).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   270
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   271
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   272
testRoundToNearestEvenAgainstIEEEDouble
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   273
	"Check that IEEE default rounding mode is honoured"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   274
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   275
	#(1 2 3 5 6 7) do: 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   276
			[:i | 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   277
			self assert: ((one timesTwoPower: 52) + (i / 4)) asTrueFraction 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   278
						= ((1 asFloat timesTwoPower: 52) + (i / 4)) asTrueFraction.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   279
			self assert: ((one timesTwoPower: 52) - (i / 4)) asTrueFraction 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   280
						= ((1 asFloat timesTwoPower: 52) - (i / 4)) asTrueFraction]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   281
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   282
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   283
testSubtract
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   284
	self assert: zero - zero = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   285
	self assert: zero - minusOne = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   286
	self assert: huge - zero = huge.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   287
	self assert: one - zero = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   288
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   289
	self assert: one - minusOne = two.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   290
	self assert: minusOne - minusTwo = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   291
	self assert: minusOne - one = minusTwo.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   292
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   293
	"check rounding"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   294
	self assert: huge - one = huge.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   295
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   296
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   297
testSum
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   298
	self assert: zero + zero = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   299
	self assert: zero + minusOne = minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   300
	self assert: huge + zero = huge.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   301
	self assert: one + zero = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   302
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   303
	self assert: one + minusOne = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   304
	self assert: minusOne + two = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   305
	self assert: one + minusTwo = minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   306
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   307
	"check rounding"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   308
	self assert: huge + one = huge.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   309
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   310
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   311
testZeroOne
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   312
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   313
	self assert: (312 asLargeFloatPrecision: 53) one = 1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   314
	self assert: (312 asLargeFloatPrecision: 24) zero isZero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   315
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   316
	self assert: (312 asLargeFloatPrecision: 53) one asInteger = 1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   317
	self assert: (312 asLargeFloatPrecision: 24) zero asInteger isZero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   318
! !
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   319
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   320
!LargeFloatTest methodsFor:'testing-coercing'!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   321
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   322
testCoercingDivide
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   323
	(Array with: 1/2 with: 0.5e0) do: [:heteroHalf |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   324
		self assert: one / heteroHalf = two.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   325
		self assert: (one / heteroHalf) class = one class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   326
		self assert: (one / heteroHalf) precision = one precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   327
		self assert: heteroHalf / one = half.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   328
		self assert: (heteroHalf / one) class = one class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   329
		self assert: (heteroHalf / one) precision = one precision].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   330
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   331
	self assert: one / 2 = half.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   332
	self assert: (one / 2) class = one class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   333
	self assert: (one / 2) precision = one precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   334
	self assert: -2 / two = minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   335
	self assert: (-2 / two) class = two class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   336
	self assert: (-2 / two) precision = two precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   337
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   338
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   339
testCoercingEqual
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   340
	self assert: half = (1/2).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   341
	self assert: (1/2) = half.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   342
	self deny: half = (1/3).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   343
	self deny: (1/3) = half.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   344
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   345
	self assert: two = 2.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   346
	self assert: -2 = minusTwo.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   347
	self deny: -3 = two.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   348
	self deny: two = 3.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   349
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   350
	self assert: half = (0.5e0).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   351
	self assert: (0.5e0) = half.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   352
	self deny: half = (0.33e0).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   353
	self deny: (0.33e0) = half.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   354
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   355
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   356
testCoercingLessThan
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   357
	self deny: half < (1/2).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   358
	self assert: (1/3) < half.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   359
	self assert: minusOne < (1/2).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   360
	self deny: (1/3) < minusTwo.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   361
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   362
	self assert: two < 3.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   363
	self deny: two < 2.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   364
	self deny: two < 1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   365
	self deny: two < -1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   366
	self assert:  minusTwo < -1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   367
	self assert:  minusTwo < 1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   368
	self deny: minusTwo < -2.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   369
	self deny: minusTwo < -3.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   370
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   371
	self deny: half < (0.5e0).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   372
	self deny: half < (0.33e0).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   373
	self assert: half < (0.66e0).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   374
	self deny: (0.5e0) < half.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   375
	self assert: (0.33e0) < half.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   376
	self deny: (0.66e0) < half.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   377
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   378
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   379
testCoercingMultiply
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   380
	(Array with: 1/2 with: 0.5e0) do: [:heteroHalf |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   381
		self assert: two * heteroHalf = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   382
		self assert: (two * heteroHalf) class = half class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   383
		self assert: (two * heteroHalf) precision = half precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   384
		self assert: heteroHalf * two = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   385
		self assert: (heteroHalf * two) class = half class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   386
		self assert: (heteroHalf * two) precision = half precision].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   387
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   388
	self assert: minusOne * 2 = minusTwo.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   389
	self assert: (minusOne * 2) class = minusOne class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   390
	self assert: (minusOne * 2) precision = minusOne precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   391
	self assert: 2 * one = two.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   392
	self assert: (2 * one) class = one class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   393
	self assert: (2 * one) precision = one precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   394
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   395
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   396
testCoercingSubtract
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   397
	(Array with: 1/2 with: 0.5e0) do: [:heteroHalf |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   398
		self assert: half - heteroHalf = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   399
		self assert: (half - heteroHalf) class = half class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   400
		self assert: (half - heteroHalf) precision = half precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   401
		self assert: heteroHalf - half = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   402
		self assert: (heteroHalf - half) class = half class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   403
		self assert: (heteroHalf - half) precision = half precision].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   404
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   405
	self assert: one - 1 = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   406
	self assert: (one - 1) class = minusOne class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   407
	self assert: (one - 1) precision = minusOne precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   408
	self assert: -2 - minusTwo = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   409
	self assert: (-2 - minusTwo) class = minusTwo class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   410
	self assert: (-2 - minusTwo) precision = minusTwo precision.
1775
68746cad01d9 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1752
diff changeset
   411
!
68746cad01d9 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1752
diff changeset
   412
2248
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   413
testCoercingSum
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   414
	(Array with: 1/2 with: 0.5e0) do: [:heteroHalf |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   415
		self assert: half + heteroHalf = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   416
		self assert: (half + heteroHalf) class = half class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   417
		self assert: (half + heteroHalf) precision = half precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   418
		self assert: heteroHalf + half = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   419
		self assert: (heteroHalf + half) class = half class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   420
		self assert: (heteroHalf + half) precision = half precision].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   421
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   422
	self assert: minusOne + 1 = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   423
	self assert: (minusOne + 1) class = minusOne class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   424
	self assert: (minusOne + 1) precision = minusOne precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   425
	self assert: 2 + minusTwo = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   426
	self assert: (2 + minusTwo) class = minusTwo class.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   427
	self assert: (2 + minusTwo) precision = minusTwo precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   428
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   429
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   430
testInfinityAndNaN
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   431
	| inf nan |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   432
	inf _ Float infinity.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   433
	nan _ Float nan.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   434
	self assert: inf + two equals: inf.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   435
	self assert: half + inf negated equals: inf negated.	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   436
	self assert: (nan + minusOne)  isNaN .
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   437
	self assert: inf - huge equals: inf.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   438
	self assert: half - inf equals: inf negated.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   439
	self assert: minusTwo - inf negated equals: inf.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   440
	self assert: (one - nan) isNaN.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   441
	self assert: inf * two equals: inf.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   442
	self assert: minusOne * inf equals: inf negated.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   443
	self assert: inf negated * minusOne equals: inf.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   444
	self assert: (huge * nan) isNaN.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   445
	self assert: inf negated / minusTwo equals: inf.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   446
	self assert: zero / inf negated equals: 0.	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   447
	self assert: one / inf equals: 0.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   448
	self should: [inf / zero] raise: ZeroDivide.	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   449
	self assert: (nan  / two) isNaN.	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   450
	self assert: (inf raisedTo: huge) equals: inf.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   451
	self assert: (huge raisedTo: inf) equals: inf.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   452
	self assert: (nan raisedTo: two) isNaN.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   453
	self assert: (two raisedTo: nan) isNaN.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   454
	self deny: nan <= one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   455
	self deny: zero >= nan.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   456
	self assert: one < inf.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   457
	self assert: zero ~= nan.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   458
	self deny: nan = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   459
! !
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   460
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   461
!LargeFloatTest methodsFor:'testing-compare'!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   462
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   463
testEqual
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   464
	self assert: zero = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   465
	self assert: one = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   466
	self assert: one = one copy.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   467
	self assert: one = (one asLargeFloatPrecision: one precision * 2).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   468
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   469
	self deny: zero = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   470
	self deny: minusOne = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   471
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   472
	self assert: zero = 0.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   473
	self assert: 0 = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   474
	self assert: zero = 0.0.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   475
	self assert: 0.0 = zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   476
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   477
	self deny: two = (1/2).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   478
	self deny: (1/2) = two.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   479
	self deny: zero = 1.0.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   480
	self deny: 0.0 = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   481
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   482
	self deny: one = nil.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   483
	self deny: nil = one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   484
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   485
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   486
testGreaterThan
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   487
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   488
	self assert: zero < one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   489
	self deny: one > two.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   490
	self deny: two > huge.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   491
	self deny: minusOne > one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   492
	self deny: minusTwo > minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   493
	self deny: minusTwo > huge.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   494
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   495
	self assert: huge > one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   496
	self assert: huge > zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   497
	self assert: huge > minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   498
	self assert: one > minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   499
	self assert: minusOne > minusTwo.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   500
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   501
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   502
testIsZero
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   503
	self assert: zero isZero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   504
	self deny: one isZero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   505
	self deny: minusTwo isZero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   506
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   507
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   508
testLessThan
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   509
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   510
	self assert: zero < one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   511
	self assert: one < two.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   512
	self assert: two < huge.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   513
	self assert: minusOne < one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   514
	self assert: minusTwo < minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   515
	self assert: minusTwo < huge.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   516
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   517
	self deny: huge < one.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   518
	self deny: huge < zero.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   519
	self deny: huge < minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   520
	self deny: one < minusOne.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   521
	self deny: minusOne < minusTwo.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   522
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   523
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   524
testNegative
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   525
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   526
	self deny: zero negative.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   527
	self deny: two negative.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   528
	self assert: minusTwo negative.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   529
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   530
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   531
testPositive
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   532
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   533
	self assert: zero positive.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   534
	self assert: one positive.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   535
	self deny: minusOne positive.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   536
! !
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   537
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   538
!LargeFloatTest methodsFor:'testing-converting'!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   539
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   540
testAsFloat
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   541
	self assert: (half asLargeFloatPrecision: Float precision) asFloat = 0.5e0.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   542
	self assert: (half asLargeFloatPrecision: Float precision * 2) asFloat = 0.5e0.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   543
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   544
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   545
testAsFloatWithUnderflow
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   546
	| fmin fminA |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   547
	fmin _ Float fmin.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   548
	fminA _ fmin asLargeFloatPrecision: one precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   549
	Float emin - Float precision + 1 to: Float emin + 1 do: [:n |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   550
		self assert: ((one timesTwoPower: n) + fminA) asFloat = ((1.0e0 timesTwoPower: n) + fmin)].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   551
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   552
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   553
testAsMinimalDecimalFraction
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   554
	| emax emin leadingOne significands |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   555
	significands _ 0 to: 1<<10-1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   556
	leadingOne _ 1<<10.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   557
	emin _ -14.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   558
	emax _ 15.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   559
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   560
	"Test all normal finite half precision float"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   561
	emin to: emax do: [:e | 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   562
		significands do: [:s |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   563
			| f |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   564
			f _ (leadingOne + s asLargeFloatPrecision: 11) timesTwoPower: e - 10.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   565
			self assert: (f asMinimalDecimalFraction asLargeFloatPrecision: 11) = f]].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   566
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   567
	"Test all subnormal finite half precision float"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   568
	significands do: [:s |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   569
		| f |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   570
		f _ (s asLargeFloatPrecision: s highBit) timesTwoPower: emin - 10.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   571
		self assert: (f asMinimalDecimalFraction asLargeFloatPrecision: s highBit) = f].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   572
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   573
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   574
testPrintAndEvaluate
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   575
	<timeout: 50 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   576
	| emax emin leadingOne significands |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   577
	significands _ 0 to: 1<<10-1.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   578
	leadingOne _ 1<<10.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   579
	emin _ -14.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   580
	emax _ 15.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   581
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   582
	"Test all normal finite half precision float"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   583
	emin to: emax do: [:e | 
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   584
		significands do: [:s |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   585
			| f |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   586
			f _ (leadingOne + s asLargeFloatPrecision: 11) timesTwoPower: e - 10.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   587
			self assert: (Compiler evaluate: f storeString) = f.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   588
			self assert: (Compiler evaluate: f printString) = f.]].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   589
	
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   590
	"Test all subnormal finite half precision float"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   591
	significands do: [:s |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   592
		| f |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   593
		f _ (s asLargeFloatPrecision: s highBit) timesTwoPower: emin - 10.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   594
		self assert: (Compiler evaluate: f storeString) = f.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   595
		self assert: (Compiler evaluate: f printString) = f].
204
7a02eaf7f06b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   596
! !
1070
3a47933aea21 category
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   597
2248
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   598
!LargeFloatTest methodsFor:'testing-functions'!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   599
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   600
testExp
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   601
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   602
	| badExp serie |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   603
	serie _ ((-20 to: 20) collect: [:e |e asFloat]).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   604
	badExp _ self checkDoublePrecisionSerieVsFloat: serie forFunction: #exp.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   605
	badExp isEmpty ifFalse: [Transcript cr; show: 'bad exp for ' , badExp printString]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   606
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   607
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   608
testExpLn
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   609
	|n|
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   610
	self assert: (1 asLargeFloatPrecision: 53) exp asFloat = 1 asFloat exp.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   611
	n _ 5 exp.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   612
	self assert: ((5 asLargeFloatPrecision: 53) exp - n)abs <= n ulp.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   613
	"self assert: (5 asLargeFloatPrecision: 53) exp asFloat = 5 asFloat exp."
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   614
	self assert: ((5 asLargeFloatPrecision: 53) exp ln asFloat - n ln)abs <= 5.0 ulp.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   615
	"this test was skipped. changed that & loosened 2. test,
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   616
	 since '5 exp' seems to round up instead of down here,
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   617
	 which results in an error of almost one ulp in '5 exp'"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   618
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   619
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   620
testLn
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   621
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   622
	| badLn serie |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   623
	serie _ ((1 to: 100) collect: [:e |e asFloat]).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   624
	badLn _ self checkDoublePrecisionSerieVsFloat: serie forFunction: #ln.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   625
	badLn isEmpty ifFalse: [Transcript cr; show: 'bad ln for ' , badLn printString]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   626
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   627
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   628
testLnDomainError
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   629
	self should: [(-2 asLargeFloatPrecision: 24) ln] raise: DomainError.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   630
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   631
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   632
testSqrt
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   633
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   634
	| badSqrt serie |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   635
	"knowing that (10**3) < (2**10), 100 bits are enough for representing 10**30 exactly"
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   636
	self assert: ((10 raisedTo: 30) asLargeFloatPrecision: 100) sqrt = (10 raisedTo: 15).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   637
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   638
	serie _ ((0 to: 20) collect: [:e | e asFloat]) , ((2 to: 20) collect: [:e | e reciprocal asFloat]).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   639
	badSqrt _ self checkDoublePrecisionSerieVsFloat: serie forFunction: #sqrt.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   640
	badSqrt isEmpty ifFalse: [Transcript cr; show: 'bad sqrt for ' , badSqrt printString]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   641
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   642
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   643
testSqrtDomainError
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   644
	self should: [(-2 asLargeFloatPrecision: 24) sqrt] raise: DomainError.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   645
! !
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   646
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   647
!LargeFloatTest methodsFor:'testing-hyperbolic'!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   648
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   649
hyperbolicSerie
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   650
	^#(-3.0e0  -0.1e0  0.0e0  1.0e-20  1.0e-10  0.99e0 1.0e0  2.5e0  3.0e0  10.25e0) , (Array with: (3/10) asFloat with: (22/7) asFloat)
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   651
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   652
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   653
testArCosh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   654
	<timeout: 5 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   655
	| serie |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   656
	serie _ ((1 to: 10) , #(1.0001 100 1000 1.0e20)) collect: [:e | e asFloat].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   657
	self checkDoublePrecisionSerie: serie forFunction: #arCosh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   658
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   659
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   660
testArCoshDomainError
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   661
	self should: [(1/2 asLargeFloatPrecision: 24) arCosh] raise: DomainError.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   662
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   663
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   664
testArSinh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   665
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   666
	| serie |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   667
	serie _ ((-5 to: 10) , #(1.0e-20 1.0e-10  0.9999 1.0001 100 1000 1.0e20)) collect: [:e | e asFloat].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   668
	self checkDoublePrecisionSerie: serie forFunction: #arSinh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   669
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   670
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   671
testArTanh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   672
	<timeout: 20 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   673
	| serie |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   674
	serie _ ((-19 to: 19) collect: [:e | (e / 20) asFloat]) , ((-6 to: 6) collect: [:e | (e / 7) asFloat]) , #(1.0e-20 1.0e-10 0.99 0.9999 0.999999).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   675
	self checkDoublePrecisionSerie: serie forFunction: #arTanh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   676
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   677
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   678
testArTanhDomainError
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   679
	self should: [(2 asLargeFloatPrecision: 24) arTanh] raise: DomainError.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   680
	self should: [(-3 asLargeFloatPrecision: 24) arTanh] raise: DomainError.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   681
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   682
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   683
testCosh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   684
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   685
	self checkDoublePrecisionSerie: self hyperbolicSerie forFunction: #cosh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   686
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   687
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   688
testSinh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   689
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   690
	self checkDoublePrecisionSerie: self hyperbolicSerie forFunction: #sinh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   691
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   692
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   693
testTanh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   694
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   695
	self checkDoublePrecisionSerie: self hyperbolicSerie forFunction: #tanh
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   696
! !
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   697
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   698
!LargeFloatTest methodsFor:'testing-trigonometry'!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   699
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   700
inverseTrigonometricSerie
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   701
	^((-20 to: 20) collect: [:e | (e / 20) asFloat]) , ((-6 to: 6) collect: [:e | (e / 7) asFloat])
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   702
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   703
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   704
largeTrigonometricSerie
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   705
	^#(1.0e15 1.1e21 1.2e28 1.0e32 1.1e34 -1.23e51 1.345e67 1.777e151 1.211e308)
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   706
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   707
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   708
testArcCos
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   709
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   710
	| badArcCos |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   711
	badArcCos _ self checkDoublePrecisionSerieVsFloat: self inverseTrigonometricSerie forFunction: #arcCos.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   712
	badArcCos isEmpty ifFalse: [Transcript cr; show: 'bad arcCos for ' , badArcCos printString]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   713
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   714
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   715
testArcCosDomainError
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   716
	self should: [(2 asLargeFloatPrecision: 24) arcCos] raise: DomainError.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   717
	self should: [(-3 asLargeFloatPrecision: 24) arcCos] raise: DomainError.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   718
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   719
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   720
testArcSin
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   721
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   722
	| badArcSin |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   723
	badArcSin _ self checkDoublePrecisionSerieVsFloat: self inverseTrigonometricSerie forFunction: #arcSin.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   724
	badArcSin isEmpty ifFalse: [Transcript cr; show: 'bad arcSin for ' , badArcSin printString]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   725
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   726
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   727
testArcSinDomainError
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   728
	self should: [(2 asLargeFloatPrecision: 24) arcSin] raise: DomainError.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   729
	self should: [(-3 asLargeFloatPrecision: 24) arcSin] raise: DomainError.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   730
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   731
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   732
testArcTan
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   733
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   734
	| badArcTan serie |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   735
	serie _ ((-50 to: 50) collect: [:e | (e / 10) asFloat]).
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   736
	badArcTan _ self checkDoublePrecisionSerieVsFloat: serie forFunction: #arcTan.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   737
	badArcTan isEmpty ifFalse: [Transcript cr; show: 'bad arcTan for ' , badArcTan printString]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   738
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   739
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   740
testArcTan2
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   741
	<timeout: 30 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   742
	-5 to: 5 by: 4/10 do: [:y |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   743
		| yf yd |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   744
		yf _ y asLargeFloatPrecision: Float precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   745
		yd _ yf asLargeFloatPrecision: Float precision * 2.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   746
		-5 to: 5 by: 4/10 do: [:x |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   747
			| xf xd  |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   748
			xf _ x asLargeFloatPrecision: Float precision.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   749
			xd _ xf asLargeFloatPrecision: Float precision * 2.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   750
			self assert: ((yd arcTan: xd) asFloat - (yf arcTan: xf) asFloat) isZero]].
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   751
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   752
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   753
testCos
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   754
	<timeout: 30 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   755
	| badCos |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   756
	badCos _ self checkDoublePrecisionSerieVsFloat: self trigonometricSerie forFunction: #cos.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   757
	badCos isEmpty ifFalse: [Transcript cr; show: 'bad cos for angles (degrees) ' , (badCos collect: [:i | i radiansToDegrees rounded]) printString]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   758
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   759
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   760
testSin
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   761
	<timeout: 30 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   762
	| badSin |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   763
	badSin _ self checkDoublePrecisionSerieVsFloat: self trigonometricSerie forFunction: #sin.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   764
	badSin isEmpty ifFalse: [Transcript cr; show: 'bad sin for angles (degrees) ' , (badSin collect: [:i | i radiansToDegrees rounded]) printString]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   765
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   766
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   767
testSincos
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   768
	<timeout: 30 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   769
	self trigonometricSerie do: [:aFloat |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   770
		| x sc s c |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   771
		x _ aFloat asLargeFloatPrecision: 53.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   772
		sc _ x sincos.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   773
		s _ x sin.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   774
		c _ x cos.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   775
		self assert: sc size = 2.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   776
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   777
		self assert: sc first = s.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   778
		self assert: sc last = c]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   779
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   780
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   781
testTan
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   782
	<timeout: 30 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   783
	| badTan |
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   784
	badTan _ self checkDoublePrecisionSerieVsFloat: self trigonometricSerie forFunction: #tan.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   785
	badTan isEmpty ifFalse: [Transcript cr; show: 'bad tan for angles (degrees) ' , (badTan collect: [:i | i radiansToDegrees rounded]) printString]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   786
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   787
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   788
testVeryLargeCos
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   789
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   790
	self checkDoublePrecisionSerie: self largeTrigonometricSerie forFunction: #cos.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   791
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   792
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   793
testVeryLargeSin
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   794
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   795
	self checkDoublePrecisionSerie: self largeTrigonometricSerie forFunction: #sin.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   796
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   797
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   798
testVeryLargeTan
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   799
	<timeout: 10 "seconds">
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   800
	self checkDoublePrecisionSerie: self largeTrigonometricSerie forFunction: #tan.
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   801
!
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   802
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   803
trigonometricSerie
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   804
	^(-720 to: 720) collect: [:i | i asFloat degreesToRadians]
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   805
! !
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   806
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   807
55f846f2839b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   808