Issue Details (XML | Word | Printable)

Key: JSCIENCE-98
Type: Bug Bug
Status: Open Open
Priority: Blocker Blocker
Assignee: jscience-issues
Reporter: littlea11
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
jscience

Real.valueOf(doubleValue) doesn't work if doubleValue is negative

Created: 23/Jul/08 07:21 AM   Updated: 31/Jan/11 02:49 AM
Component/s: www
Affects Version/s: current
Fix Version/s: Version 6.0

Time Tracking:
Not Specified

Environment:

Operating System: All
Platform: All


Issuezilla Id: 98
Tags:
Participants: jscience-issues and littlea11


 Description  « Hide

I get an AritmeticException when doing the following:

Real number = Real.valueOf(-3.3254);

The exception is:

Exception in thread "main" java.lang.ArithmeticException: Negative number or
zero
at javolution.lang.MathLib.floorLog2(Unknown Source)
at javolution.lang.MathLib.floorLog10(Unknown Source)
at org.jscience.mathematics.number.Real.valueOf(Real.java:203)
at com.ml.pa.scenarios.Master.main(Master.java:103)

But it is ok if I do

Real number = Real.valueOf(-3);

I can get around it by doing:

Real number = Real.valueOf(3.3254);
number.times(-1);

Here is the code of Real.valueOf:

-------------------------------------------------------------
/**

  • Returns the real number (inexact except for <code>0.0</code>)
  • corresponding to the specified <code>double</code> value.
  • The error is derived from the inexact representation of
  • <code>double</code> values intrinsic to the 64 bits IEEE 754 format.
  • @param doubleValue the <code>double</code> value to convert.
  • @return the corresponding real number.
    */
    public static Real valueOf(double doubleValue) { if (doubleValue == 0.0) return Real.ZERO; if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) return Real.NaN; // Find the exponent e such as: value == x.xxx * 10^e int e = MathLib.floorLog10(doubleValue) - 18 + 1; // 18 digits significand. long significand = MathLib.toLongPow10(doubleValue, -e); int error = (int) MathLib.toLongPow10(Math.ulp(doubleValue), -e) + 1; return Real.valueOf(LargeInteger.valueOf(significand), error, e); }

------------------------------------------------------------------------
If MathLib.floorLog10 does what the name says, it won't work unless the
argument is greater than zero.



There are no comments yet on this issue.