Bug 48359

Summary: ARM SOFTFP double to ascii issue still there
Product: classpath Reporter: Gert Brettlecker <gert.brettlecker>
Component: classpathAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal CC: aph, ramana
Priority: P3    
Version: 0.98   
Target Milestone: ---   
See Also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22800
Host: Target: arm
Build: Known to work:
Known to fail: Last reconfirmed:

Description Gert Brettlecker 2011-03-30 09:40:06 UTC
Hi 

I have seen http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22800. 

I am using the fixed version (0.98). But there is still a problem with double to string conversion in Java_lang_VMDouble.c and I am running into the assertion there.

My platform is arm-v5te without hardware FPU using gcc 4.3.2 with -mfloat-abi=soft. There I found out, that the addition of two denormalized double 64 bit numbers are sometimes producing wrong results, e.g. the sum is smaller than the bigger one even though both are positive. If one number is normalized there is no more problem.  

But in cases of wrong calculation, the alorithm in Java_java_lang_VMDouble_toString runs into assertion for certain numbers. Maybe it is possible to allow that parsed_value_unequal is set only if the difference exceeds a certain threshold and if it is not exactly the same.

Cheers
Gert
Comment 1 Gert Brettlecker 2011-03-31 13:57:21 UTC
I applied the following patch for this situation on my ARM platform.
This will loose precision on denormalized numbers (smaller than DBL_MIN) but it does not assert anymore:

--- classpath-0.98/native/jni/java-lang/java_lang_VMDouble.c
+++ classpath-0.98/native/jni/java-lang/java_lang_VMDouble.c
@@ -42,6 +42,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <float.h>
 
 #include "mprec.h"
 #include "fdlibm.h"
@@ -422,7 +423,10 @@
   do {
     jdouble parsed_value;
 
-    assert(least_necessary_precision <= maximal_precision);
+    if (least_necessary_precision>maximal_precision) {
+    	fprintf (stderr, "java.lang.VMDouble.toString error reaching maximal_precision value = %g\n", value);
+	break;
+    }
 
     /* Convert the value to a string and back. */
     dtoa_toString(buf, value, least_necessary_precision, isFloat);
@@ -433,10 +437,14 @@
     /* We need to cast floats to float to make sure that our ineqality check works
      * well for floats as well as for doubles.
      */
-    parsed_value_unequal = ( isFloat ? 
-			     (float) parsed_value != (float) value : 
-			     parsed_value != value);
-
+    if (isFloat) {
+    	parsed_value_unequal = ((float) parsed_value != (float) value) ;
+    } else if (parsed_value>value) {
+    	parsed_value_unequal = ((parsed_value-value) >  DBL_MIN);
+    } else {
+	parsed_value_unequal = ((value-parsed_value) >  DBL_MIN);
+    }
+  
     least_necessary_precision++;
   }
   while (parsed_value_unequal);

Someone has a better idea?

Cheers
Gert
Comment 2 Andrew Haley 2011-03-31 18:35:06 UTC
I'm trying to get my ARM hardware working.  Once I have, I'll have a look.
Comment 3 Ramana Radhakrishnan 2017-06-16 14:00:46 UTC
Do we still have classpath issues to look at ? 

It's been quite a few years now since the bug was reported- Andrew did you manage to reproduce this ?

Ramana