[erlang-bugs] bug in Jinterface sending doubles?

Raimo Niskanen raimo+erlang-bugs@REDACTED
Tue Dec 4 10:11:56 CET 2007


Indeed there is (a bug).

In the upcoming R12B release, Jinterface has been updated to
use IEEE term format for Erlang marshalled data, so this
bug should have vanished. We also now have at least one
test case that echoes 0.0 (and other interesting floats)
from Erlang via Jinterface.

We had no such test case in R11B-5, and that was bad.

The Jinterface code used java.math.BigDecimal and
java.text.DecimalFormat to do the old (daft) marshalling
that was based on C:s sprintf("%.20e", ...).
It was written for Java 1.2.

You seem to have run into a borderline case where
	d = roughly(0.0);
	BigDecimal b = new BigDecimal(d);
	b.signum() returns 0
	b = b.setScale(20,BigDecimal.ROUND_HALF_EVEN);
	b.toString() returns "0E-20" even though
	             b.signum() returned 0 above
So, since signum() is 0 b should be zero but
toString() returns "0E-20" with setScale(20,...)
sugessting v is just almost zero. toString() was
supposed to return "0.00000000000000000000".

Apparently in  Java 1.3 java.math.BigDecimal(double d)
changed behaviour to allow optional exponent sign.
Perhaps something else changed too...

Anyway... the bug should be gone in R12B.



On Mon, Dec 03, 2007 at 05:15:30PM +0100, Sebastian Egner wrote:
> Hello!
> 
> There seems to be a bug in Jinterface (from R11B-5) related to sending 
> doubles from a Java node to an Erlang node:
> 
> =ERROR REPORT==== 3-Dec-2007::16:56:35 ===
> Got invalid data on distribution channel, offending packet is: 
> <<112,131,104,4,97,6,103,100,0,19,115,112,101,99,115,112,108,97,110,64,103,111,108,100,115,116,111,110,101,0,0,0,1,0,0,0,0,1,100,0,0,100,0,2,102,103,131,104,3,100,0,9,36,103,101,110,95,99,97,108,108,104,2,103,100,0,19,115,112,101,99,115,112,108,97,110,64,103,111,108,100,115,116,111,110,101,0,0,0,1,0,0,0,0,1,114,0,3,100,0,19,115,112,101,99,115,112,108,97,110,64,103,111,108,100,115,116,111,110,101,1,0,0,0,13,0,0,0,0,0,0,0,0,104,3,100,0,7,115,101,116,95,118,97,108,100,0,7,117,101,110,101,114,103,121,99,48,69,45,50,48,101,43,48,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>
> 
> My guess is that the offending value, the notorious (double)0.0, is not 
> properly encoded by OtpOutputStream.write_double():
> 
>  > io:format("~s~n", [TheStuffAboveAsAListOfAsciiValues]).
> "blabla...uenergyc0E-20e+00...moreblabla"
> 
> Sebastian.
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-bugs

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-bugs mailing list