[m-rev.] diff: define sinh, cosh and tanh as foreign_procs in Java grade
Julien Fischer
jfischer at opturion.com
Wed Jun 25 17:26:31 AEST 2014
Branches: 14.01, master
Use foreign_procs to define the hyperbolic operations in the Java grade.
Java has provided these since version 1.5 and since that is the minimum
version required by Mercury we can rely on them being present.
library/math.m:
As above.
Julien.
diff --git a/library/math.m b/library/math.m
index d6a0fc9..78c22d3 100644
--- a/library/math.m
+++ b/library/math.m
@@ -918,6 +918,12 @@ math.acos(X) = ACos :-
"
Sinh = sinh(X);
").
+:- pragma foreign_proc("Java",
+ math.sinh(X::in) = (Sinh::out),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ Sinh = java.lang.Math.sinh(X);
+").
:- pragma foreign_proc("C#",
math.sinh(X::in) = (Sinh::out),
[will_not_call_mercury, promise_pure, thread_safe],
@@ -930,7 +936,7 @@ math.acos(X) = ACos :-
"
Sinh = math:sinh(X)
").
-% Java doesn't have any hyperbolic functions built in.
+% Version for back-ends that do not have a foreign_proc version.
math.sinh(X) = Sinh :-
Sinh = (exp(X)-exp(-X)) / 2.0.
@@ -941,6 +947,12 @@ math.sinh(X) = Sinh :-
"
Cosh = cosh(X);
").
+:- pragma foreign_proc("Java",
+ math.cosh(X::in) = (Cosh::out),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ Cosh = java.lang.Math.cosh(X);
+").
:- pragma foreign_proc("C#",
math.cosh(X::in) = (Cosh::out),
[will_not_call_mercury, promise_pure, thread_safe],
@@ -953,7 +965,7 @@ math.sinh(X) = Sinh :-
"
Cosh = math:cosh(X)
").
-% Java doesn't have any hyperbolic functions built in.
+% Version for back-ends that do not have a foreign_proc version.
math.cosh(X) = Cosh :-
Cosh = (exp(X)+exp(-X)) / 2.0.
@@ -964,6 +976,12 @@ math.cosh(X) = Cosh :-
"
Tanh = tanh(X);
").
+:- pragma foreign_proc("Java",
+ math.tanh(X::in) = (Tanh::out),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ Tanh = java.lang.Math.tanh(X);
+").
:- pragma foreign_proc("C#",
math.tanh(X::in) = (Tanh::out),
[will_not_call_mercury, promise_pure, thread_safe],
@@ -976,7 +994,7 @@ math.cosh(X) = Cosh :-
"
Tanh = math:tanh(X)
").
-% Java doesn't have any hyperbolic functions built in.
+% Version for back-ends that do not have a foreign_proc version.
math.tanh(X) = Tanh :-
Tanh = (exp(X)-exp(-X)) / (exp(X)+exp(-X)).
More information about the reviews
mailing list