[m-rev.] diff: fix the behaviour of math.round/1 in the Java grade
Julien Fischer
jfischer at opturion.com
Thu Sep 6 23:09:50 AEST 2018
Fix the behaviour of math.round/1 in the Java grade.
library/math.m:
Implement the documented behaviour for infinities for
math.round/1 in the Java grade.
Julien.
diff --git a/library/math.m b/library/math.m
index 74cf915..db583da 100644
--- a/library/math.m
+++ b/library/math.m
@@ -455,7 +455,14 @@ e = 2.7182818284590452353602874713526625.
round(Num::in) = (Rounded::out),
[will_not_call_mercury, promise_pure, thread_safe],
"
- Rounded = java.lang.Math.round(Num);
+ // For +/- infinity Java's round method will return Long.{MAX,MIN}_VALUE.
+ // This does not match the documented Mercury behaviour for round with
+ // infinities.
+ if (java.lang.Double.isInfinite(Num)) {
+ Rounded = Num;
+ } else {
+ Rounded = java.lang.Math.round(Num);
+ }
").
:- pragma foreign_proc("Erlang",
round(Num::in) = (Rounded::out),
More information about the reviews
mailing list