You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/03/01 01:05:23 UTC
[groovy] branch master updated (c2e34c6 -> 5934481)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git.
from c2e34c6 change jcenter references to Maven Central in build (but leave reference needed currently for asciidoctorj-groovy-dsl)
new a045651 GROOVY-9797: Take negative zero floats into account by using Float.equals
new ea96d88 GROOVY-9797: Take also negative zero doubles into account by using Double.equals
new b3042bb GROOVY-9797: Implemented tests for float.
new 5934481 GROOVY-9797: Implemented tests for double. (closes #1504)
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../codehaus/groovy/classgen/asm/OperandStack.java | 6 +-
src/test/groovy/bugs/Groovy9797.groovy | 64 ++++++++++++++++++++++
2 files changed, 68 insertions(+), 2 deletions(-)
create mode 100644 src/test/groovy/bugs/Groovy9797.groovy
[groovy] 04/04: GROOVY-9797: Implemented tests for double. (closes
#1504)
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 5934481ae0e7427d83e0c698ffec846f131bdb06
Author: Otto Vayrynen <ot...@tuni.fi>
AuthorDate: Sat Feb 27 16:45:02 2021 +0200
GROOVY-9797: Implemented tests for double. (closes #1504)
---
src/test/groovy/bugs/Groovy9797.groovy | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/test/groovy/bugs/Groovy9797.groovy b/src/test/groovy/bugs/Groovy9797.groovy
index 0e588ff..1e71873 100644
--- a/src/test/groovy/bugs/Groovy9797.groovy
+++ b/src/test/groovy/bugs/Groovy9797.groovy
@@ -46,4 +46,19 @@ class Groovy9797 extends GroovyTestCase {
int positiveZeroBits = Float.floatToIntBits(0.0f)
assertNotSame(negativeZeroBits, positiveZeroBits)
}
+
+ // Test with string conversion
+ void testDoubleToString() {
+ double negativeZero = -0.0d
+ double positiveZero = 0.0d
+ assertToString(negativeZero, '-0.0')
+ assertToString(positiveZero, '0.0')
+ }
+
+ // Test with long bits
+ void testNegativePositiveZeroDoubleLongBitsNotSame() {
+ long negativeZeroBits = Double.doubleToLongBits(-0.0d)
+ long positiveZeroBits = Double.doubleToLongBits(0.0d)
+ assertNotSame(negativeZeroBits, positiveZeroBits)
+ }
}
[groovy] 03/04: GROOVY-9797: Implemented tests for float.
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit b3042bbc8bf986952ef692c92b139b9dc1b0c787
Author: Iiro Kiviluoma <ii...@outlook.com>
AuthorDate: Thu Feb 25 10:26:42 2021 +0200
GROOVY-9797: Implemented tests for float.
---
src/test/groovy/bugs/Groovy9797.groovy | 49 ++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/src/test/groovy/bugs/Groovy9797.groovy b/src/test/groovy/bugs/Groovy9797.groovy
new file mode 100644
index 0000000..0e588ff
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9797.groovy
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs
+
+import groovy.test.GroovyTestCase
+
+/*
+ * About bug fix:
+ * According to the IEEE-754 floating point standard, the sign of a negative zero
+ * must be preserved. However, when Groovy compiles code, it uses the ==
+ * operator to compare floats and uses the special constant instruction for
+ * (positive) zero if the float is equal to zero. The == operator does not
+ * differentiate between positive and negative zero, which complies with the
+ * standard. This fix uses Float.equals which can differentiate between positive
+ * and negative zero.
+ */
+
+class Groovy9797 extends GroovyTestCase {
+ // Test with string conversion
+ void testFloatToString() {
+ float negativeZero = -0.0f
+ float positiveZero = 0.0f
+ assertToString(negativeZero, '-0.0')
+ assertToString(positiveZero, '0.0')
+ }
+
+ // Test with int bits
+ void testNegativePositiveZeroFloatIntBitsNotSame() {
+ int negativeZeroBits = Float.floatToIntBits(-0.0f)
+ int positiveZeroBits = Float.floatToIntBits(0.0f)
+ assertNotSame(negativeZeroBits, positiveZeroBits)
+ }
+}
[groovy] 01/04: GROOVY-9797: Take negative zero floats into account
by using Float.equals
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit a04565113232d538be9af486cbf9ebdd55dfb509
Author: Esko Toivonen <es...@tuni.fi>
AuthorDate: Tue Feb 23 16:50:50 2021 +0200
GROOVY-9797: Take negative zero floats into account by using Float.equals
According to the IEEE-754 floating point standard, the sign of a negative zero
must be preserved. However, when Groovy compiles code, it uses the ==
operator to compare floats and uses the special constant instruction for
(positive) zero if the float is equal to zero. The == operator does not
differentiate between positive and negative zero, which complies with the
standard. This fix uses Float.equals which can differentiate between positive
and negative zero.
---
src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java b/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
index 475e250..2e23cca 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
@@ -540,7 +540,8 @@ public class OperandStack {
mv.visitLdcInsn(value);
}
} else if (ClassHelper.float_TYPE.equals(type)) {
- if ((Float)value==0f) {
+ // GROOVY-9797: Use Float.equals to differentiate between positive and negative zero
+ if (value.equals(0f)) {
mv.visitInsn(FCONST_0);
} else if ((Float)value==1f) {
mv.visitInsn(FCONST_1);
[groovy] 02/04: GROOVY-9797: Take also negative zero doubles into
account by using Double.equals
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit ea96d8862770d73ababfc2cc36cc7045edf942a5
Author: Eerik Voimanen <ee...@tuni.fi>
AuthorDate: Tue Feb 23 17:28:43 2021 +0200
GROOVY-9797: Take also negative zero doubles into account by using Double.equals
Doubles are also IEEE-754 floating point numbers.
---
src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java b/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
index 2e23cca..eed81c2 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
@@ -551,7 +551,8 @@ public class OperandStack {
mv.visitLdcInsn(value);
}
} else if (ClassHelper.double_TYPE.equals(type)) {
- if ((Double)value==0d) {
+ // GROOVY-9797: Use Double.equals to differentiate between positive and negative zero
+ if (value.equals(0d)) {
mv.visitInsn(DCONST_0);
} else if ((Double)value==1d) {
mv.visitInsn(DCONST_1);