RegressionTests__FloatTest.st
changeset 263 c28dd8e5c799
parent 257 94924ee6840b
child 604 d3bb339b9ab8
--- a/RegressionTests__FloatTest.st	Tue Apr 12 12:36:24 2005 +0200
+++ b/RegressionTests__FloatTest.st	Thu Apr 14 21:21:30 2005 +0200
@@ -3,10 +3,10 @@
 "{ NameSpace: RegressionTests }"
 
 TestCase subclass:#FloatTest
-        instanceVariableNames:''
-        classVariableNames:''
-        poolDictionaries:''
-        category:'tests-Regression'
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'tests-Regression'
 !
 
 
@@ -364,6 +364,8 @@
     check value:-30 value:1.
     check value:-1 value:30.
 
+    self assert:( 200000000000000000000.0 = 200000000000000000001 ).
+
     self assert:( 200000000000000000000.0 = 200000000000000000000 ).
     self assert:( 200000000000000000000.0 asLongFloat = 200000000000000000000 ).
     self assert:( 2000000.0 asShortFloat = 2000000 ).
@@ -402,52 +404,157 @@
 !
 
 test06_MiscMath
+    |epsilon|
+
+    epsilon := 0.000001.
+
     #(
-        sqrt       0.5
-        exp        0.5
-        ln         0.5
-        log10      0.5
-        sin        0.5
-        cos        0.5
-        tan        0.5
-        arcSin     0.5
-        arcCos     0.5
-        arcTan     0.5
-        sinh       0.5 
-        cosh       0.5
-        tanh       0.5
-        arcSinh    0.5
-        arcCosh    1.5
-        arcTanh    0.5
+        sqrt       0.5       0.707107
+        exp        0.5       1.64872
+        ln         0.5       -0.693147
+        log10      0.5       -0.30103
+
+        sin        0.5      0.479426
+        cos        0.5      0.877583
+        tan        0.5      0.546302 
+        arcSin     0.5      0.523599
+        arcCos     0.5      1.0472
+        arcTan     0.5      0.463648  
+        sinh       0.5      0.521095
+        cosh       0.5      1.12763
+        tanh       0.5      0.462117
+        arcSinh    0.5      0.481212
+        arcCosh    1.5      1.24983
+        arcTanh    0.5      0.549306
+
+        sin        0.0      0.0
+        cos        0.0      1.0
+        tan        0.0      0.0  
+        sinh       0.0      0.0
+        cosh       0.0      1.0
+        tanh       0.0      0.0
+
+        sin        1.0      0.841471
+        cos        1.0      0.540302
+        tan        1.0      1.55741
+        sinh       1.0      1.1752
+        cosh       1.0      1.54308
+        tanh       1.0      0.761594
+
+        sin        3.14159  0.0
+        cos        3.14159  -1.0
+        tan        3.14159  0.0
+        sinh       3.14159  11.5487 
+        cosh       3.14159  11.5919   
+        tanh       3.14159  0.996272
+
+
+        tan        0.785398 1.0         "pi/4  -> should be 1"
+        arcCos     -1.0     3.14159     "should be pi"
+        arcSin     1.0      1.5708      "should be pi/2 (1.5708)"
+        arcTan     1.0      0.785398    "should be pi/4 (.785398)"
+    ) inGroupsOf:3 do:[:op :x :expected|
+        |rslt rsltShortFloat rsltLongFloat rsltLargeFloat|
+
+        rslt := x perform:op.
+        rsltShortFloat := x asShortFloat perform:op.
+        rsltLongFloat := x asLongFloat perform:op.
+"/        rsltLargeFloat := arg asLargeFloat perform:op.
+
+        self assert:(rslt class == Float).
+        self assert:(rsltShortFloat class == Float).  "/ ???
+        self assert:(rsltLongFloat class == LongFloat).
+
+        self assert:( rslt - rsltShortFloat ) < epsilon.
+        self assert:( rslt - rsltLongFloat ) < epsilon.
+"/        self assert:( rslt - rsltLargeFloat ) < epsilon.
+        self assert:( rslt - rslt asShortFloat ) < epsilon.
+        self assert:( rslt - rslt asLongFloat ) < epsilon.
+"/        self assert:( rslt - rslt asLargeFloat ) < epsilon.
+    ].
+
+    self should:[ -2 arcSin ] raise:DomainError.
+    self should:[ -2 arcCos ] raise:DomainError.
+    self should:[ -1 arcTanh ] raise:DomainError.
 
-        sin        0.0
-        cos        0.0
-        tan        0.0
-        sinh       0.0 
-        cosh       0.0
-        tanh       0.0
+    #(
+        0.0
+        0.5
+        1.0
+        2.0
+        1.57079
+     ) do:[:x |
+        self assert:( x sin arcSin - x < epsilon).
+        self assert:( x cos arcCos - x < epsilon).
+        self assert:( x tan arcTan - x < epsilon).
+    ].
 
-        sin        1.0
-        cos        1.0
-        tan        1.0
-        sinh       1.0 
-        cosh       1.0
-        tanh       1.0
+    #(
+        -1.0
+        -0.5
+        0.0
+        0.5
+        1.0
+     ) do:[:x |
+        self assert:( x arcSin sin - x < epsilon).
+        self assert:( x arcCos cos - x < epsilon).
+        self assert:( x arcTan tan - x < epsilon).
+    ].
 
-    ) pairWiseDo:[:op :arg |
-        self assert:( arg perform:op ) class == Float.
-        self assert:( arg asShortFloat perform:op ) class == Float.
-        self assert:( arg asLongFloat perform:op ) class == LongFloat.
-        ( arg asLongFloat perform:op ) class == LongFloat ifFalse:[
-            Transcript showCR:'warning: missing LongFloat function: ' , op.
-        ].
+    #(
+        0.0
+        0.5
+        1.0
+        2.0
+        10
+     ) do:[:x |
+        self assert:( x cosh arcCosh - x < epsilon).
+    ].
+    #(
+        -10
+        -2
+        -1
+        -0.5
+        0.0
+        0.5
+        1.0
+        2.0
+        10
+     ) do:[:x |
+        self assert:( x sinh arcSinh - x < epsilon).
+        self assert:( x tanh arcTanh - x < epsilon).
+    ].
+
 
-        self assert:( (arg perform:op) - (arg asShortFloat perform:op) ) < 0.000001.
-        self assert:( (arg perform:op) - (arg asLongFloat perform:op) ) < 0.000001.
-"/        self assert:( (arg perform:op) - (arg asLargeFloat perform:op) ) < 0.000001.
-        self assert:( (arg perform:op) - (arg perform:op) asShortFloat ) < 0.000001.
-        self assert:( (arg perform:op) - (arg perform:op) asLongFloat ) < 0.000001.
-"/        self assert:( (arg perform:op) - (arg perform:op) asLargeFloat ) < 0.000001.
+    #(
+        -0.99
+        -0.5
+        0.0
+        0.5
+        0.99
+     ) do:[:x |
+        self assert:( x arcTanh - (( ( (1+x)/(1-x) ) ln ) / 2 ) ) < epsilon.
+    ].
+
+    #(
+        -10
+        -5
+        -2.0
+        -1.0
+        0.0
+        1.0
+        2.0
+        10
+     ) do:[:x |
+        self assert:( x arcSinh sinh - x < epsilon).
+    ].
+
+    #(
+        1.0
+        2.0
+        10.0
+     ) do:[:x |
+        self assert:( x arcCosh cosh - x < epsilon).
     ].
 
     "