Java-style FP math natives and support methods jk_new_structure
authorvranyj1
Wed, 07 Sep 2011 16:38:51 +0000
branchjk_new_structure
changeset 988 414a2c9a6a9e
parent 987 7ce13ad78d68
child 989 e6977de62068
Java-style FP math natives and support methods
src/JavaMathSupport.st
src/JavaVM.st
--- a/src/JavaMathSupport.st	Wed Sep 07 16:08:51 2011 +0000
+++ b/src/JavaMathSupport.st	Wed Sep 07 16:38:51 2011 +0000
@@ -97,14 +97,53 @@
 
 !JavaMathSupport class methodsFor:'java-style FP functions'!
 
+cos:arg
+    self shouldImplement
+
+    "Created: / 07-09-2011 / 17:34:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 cosh: f
 
+%{
+	RETURN ( _MKFLOAT( jcosh ( __floatVal ( f ) ) ) );
+%}
+
     "Created: / 07-09-2011 / 17:08:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+expm1:arg
+    self shouldImplement
+
+    "Created: / 07-09-2011 / 17:34:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+floor:arg
+    self shouldImplement
+
+    "Created: / 07-09-2011 / 17:33:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sin:arg
+    self shouldImplement
+
+    "Created: / 07-09-2011 / 17:32:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 sinh: f
 
+%{
+	RETURN ( _MKFLOAT( jsinh ( __floatVal ( f ) ) ) );
+%}
+
+
     "Created: / 07-09-2011 / 17:08:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+tanh:arg
+    self shouldImplement
+
+    "Created: / 07-09-2011 / 17:32:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaMathSupport class methodsFor:'documentation'!
--- a/src/JavaVM.st	Wed Sep 07 16:08:51 2011 +0000
+++ b/src/JavaVM.st	Wed Sep 07 16:38:51 2011 +0000
@@ -5761,18 +5761,18 @@
 
     <javanative: 'java/lang/StrictMath' name: 'cbrt'>
 
-    ^ UnimplementedNativeMethodSignal raise
+    ^ JavaMathSupport cbrt: (nativeContext argAt:1)
+
+    "Modified: / 07-09-2011 / 17:34:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_lang_StrictMath_cos: nativeContext
 
     <javanative: 'java/lang/StrictMath' name: 'cos'>
 
-    | f |
-    f := nativeContext argAt: 1.
-    ^f cos
-
-    "Modified: / 08-08-2011 / 23:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    ^ JavaMathSupport cos: (nativeContext argAt:1)
+
+    "Modified: / 07-09-2011 / 17:34:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_lang_StrictMath_cosh: nativeContext
@@ -5805,12 +5805,7 @@
     public static native double cosh(double x);
     "
 
-    | f |
-    f := nativeContext argAt: 1.
-    f isNaN ifTrue:[^f].
-    f isInfinite ifTrue:[(1.0 uncheckedDivide: 0.0)].
-
-    ^f cosh
+    ^JavaMathSupport cosh: (nativeContext argAt:1)
 
     "Modified: / 06-09-2011 / 19:25:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
@@ -5819,40 +5814,36 @@
 
     <javanative: 'java/lang/StrictMath' name: 'expm1'>
 
-    ^ UnimplementedNativeMethodSignal raise
+    ^ JavaMathSupport expm1: (nativeContext argAt:1)
+
+    "Modified: / 07-09-2011 / 17:34:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_lang_StrictMath_floor: nativeContext
 
     <javanative: 'java/lang/StrictMath' name: 'floor'>
 
-    | f |
-    f := nativeContext argAt:1.
-    ^f floor
-
-    "Modified: / 10-08-2011 / 01:14:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-_java_lang_StrictMath_floot: nativeContext
-
-    <javanative: 'java/lang/StrictMath' name: 'cos'>
-
-    | f |
-    f := nativeContext argAt: 1.
-    ^f floor
-
-    "Created: / 08-08-2011 / 23:46:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+   ^ JavaMathSupport floor: (nativeContext argAt:1)
+
+    "Modified: / 07-09-2011 / 17:33:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+_java_lang_StrictMath_pow: nativeContext
+
+    <javanative: 'java/lang/StrictMath' name: 'pow(DD)D'>
+
+    ^JavaMathSupport pow: (nativeContext argAt:1) to: (nativeContext argAt:3)
+
+    "Modified: / 07-09-2011 / 17:33:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_lang_StrictMath_sin: nativeContext
 
     <javanative: 'java/lang/StrictMath' name: 'cos'>
 
-    | f |
-    f := nativeContext argAt: 1.
-    ^f sin
-
-    "Modified: / 08-08-2011 / 23:44:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    ^ JavaMathSupport sin: (nativeContext argAt:1)
+
+    "Modified: / 07-09-2011 / 17:32:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_lang_StrictMath_sinh: nativeContext
@@ -5887,14 +5878,10 @@
 
     "
 
-    | f |
-    f := nativeContext argAt: 1.
-    f isNaN ifTrue:[^f].
-    f isInfinite ifTrue:[(1.0 uncheckedDivide: 0.0)].
-
-    ^f sinh
+    ^ JavaMathSupport sinh: (nativeContext argAt:1)
 
     "Modified: / 06-09-2011 / 19:36:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 07-09-2011 / 17:31:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_lang_StrictMath_tanh: nativeContext
@@ -5933,16 +5920,9 @@
     public static native double tanh(double x);
     "
 
-    | f |
-    f := nativeContext argAt: 1.
-    f isNaN ifTrue:[^f].
-    (                      0.0) = f ifTrue:[   f].
-    ( 1.0 uncheckedDivide: 0.0) = f ifTrue:[ 1.0].
-    (-1.0 uncheckedDivide: 0.0) = f ifTrue:[-1.0].
-
-    ^f tanh
-
-    "Modified: / 06-09-2011 / 19:40:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    ^ JavaMathSupport tanh: (nativeContext argAt:1)
+
+    "Modified: / 07-09-2011 / 17:32:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_lang_String_intern: nativeContext
@@ -6025,7 +6005,11 @@
     ] ifFalse:[
         dstArrayCC isJavaPrimitiveType ifFalse:[
             1 to: count do:[:i|
-                (self canCast: (srcArray at:srcIdx + i - 1) class to: dstArrayCC) ifFalse:[
+                | obj |
+
+                obj := srcArray at:srcIdx + i - 1.
+
+                (obj isNil or:[(self canCast: obj class to: dstArrayCC) not]) ifTrue:[
                     ^ self throwArrayStoreException:dstArray
                 ].
                 dstArray at: dstIdx + i - 1 put: (srcArray at:srcIdx + i - 1)
@@ -6036,7 +6020,7 @@
     ].
     ^ nil.
 
-    "Modified: / 06-09-2011 / 20:03:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 07-09-2011 / 17:38:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 _java_lang_System_currentTimeMillis: nativeContext