jscience
  1. jscience
  2. JSCIENCE-115

FloatingPoint.valueOf and Real.valueOf throw on negative values

    Details

    • Type: Task Task
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: Version 6.0
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      115

      Description

      If you call FloatingPoint.valueOf(double) with negative values, you get an
      java.lang.ArithmeticException: Negative number or zero .

      Solution: in FloatingPoint.valueOf(double) the line
      int e = MathLib.floorLog10(doubleValue) - 18 + 1; // 18 digits significand.

      should be replaced with

      int e = MathLib.floorLog10(MathLib.abs(doubleValue)) - 18 + 1; // 18 digits
      significand.

      (This has a different cause from Issue 113 and I have already a solution, so I'm
      submitting this separately.)

      I would also suggest adding the lines
      if (doubleValue == 1.0)
      return FloatingPoint.ONE;
      to this function.

      Best regards,

      Hans-Peter

        Activity

        Hide
        hstoerr added a comment -

        The same problem with the same solution exists in Real.valueOf(double) .

        Show
        hstoerr added a comment - The same problem with the same solution exists in Real.valueOf(double) .
        Hide
        hstoerr added a comment -

        This should be a patch instead of an issue, since I included a fix.
        Tests to verify the fix are included in issue 120.

        Show
        hstoerr added a comment - This should be a patch instead of an issue, since I included a fix. Tests to verify the fix are included in issue 120.

          People

          • Assignee:
            jscience-issues
            Reporter:
            hstoerr
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: