This is an automated email from the ASF dual-hosted git repository.
mboehm7 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/systemml.git
The following commit(s) were added to refs/heads/master by this push:
new 4422a05 [SYSTEMML-2530] Fix wrong integer casting for negative numbers
4422a05 is described below
commit 4422a05325b03e0b656302774504ca9763e72c2a
Author: Matthias Boehm <[email protected]>
AuthorDate: Fri Aug 9 16:20:18 2019 +0200
[SYSTEMML-2530] Fix wrong integer casting for negative numbers
This patch backports SYSTEMDS-106 as it resolves an issue of incorrect
results that are so subtle that they might go unnoticed.
---
src/main/java/org/apache/sysml/runtime/util/UtilFunctions.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sysml/runtime/util/UtilFunctions.java
b/src/main/java/org/apache/sysml/runtime/util/UtilFunctions.java
index 42b519b..f6c1182 100644
--- a/src/main/java/org/apache/sysml/runtime/util/UtilFunctions.java
+++ b/src/main/java/org/apache/sysml/runtime/util/UtilFunctions.java
@@ -323,11 +323,13 @@ public class UtilFunctions
}
public static int toInt( double val ) {
- return (int) Math.floor( val + DOUBLE_EPS );
+ return (int) (Math.signum(val)
+ * Math.floor(Math.abs(val) + DOUBLE_EPS));
}
public static long toLong( double val ) {
- return (long) Math.floor( val + DOUBLE_EPS );
+ return (long) (Math.signum(val)
+ * Math.floor(Math.abs(val) + DOUBLE_EPS));
}
public static int toInt(Object obj) {