Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: current
    • Fix Version/s: Version 6.0
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      32

      Description

      This report is related to
      https://jscience.dev.java.net/servlets/ReadMsg?list=users&msgNo=153

      While using Real and Measure together I stumbled over a problem when specifying
      a valueOf(LargeInteger mantissa, LargeInteger error, int exponent) and
      valueOf(java.lang.CharSequence chars).

      Sample code and output are at the end of this report.

      The following questions are related to the output of the code:
      1. Why does a toString() not specify the error in its output *) ?

      *) The answer to the first question (1) I can find in an email conversation
      between Joe Kelly and Jean-Marie Dautelle on the 15th and 16th of March 2006
      that a correction on Real is planned that writes out the error as well when
      using toString().

      I guess that this question is one of the improvements Jean-Marie Dautelle are
      talking about in his answer to me about Real?

      2. Why does getError of Real return the error plus 1 when using
      valueOf(LargeInteger mantissa, LargeInteger error, int exponent) (instead of 100
      or 1E2) in TEST 1 and similar in TEST 2?

      3. The tests TEST 3 to TEST 5 with valueOf(java.lang.CharSequence chars) results
      in a, to me, strange result from getError() of Real and in one occurrence also
      the result from getMantissa() of Real:
      TEST 3: Here the error is becoming something that looks like the mantissa but
      with a larger magnitude. This results in a Real with value 0E4 because the error
      is greater than the mantissa it self.
      TEST 4: Here the mantissa and the error are wrong and the result of the Real as
      well. The mantissa of 919 seems really strange in comparison to the other
      mantissas as the mantissas till now have been without error as it seems.
      TEST 5: Here the mantissa is right but the error is wrong. And that lets the
      result of the Real become wrong.

      4. In relation to question 1 is it/will it be possible in the future to print
      out the Real value with its full information using toString(), so you will e.g.
      for TEST 2 get:
      12345600 ± 2501, 123456E2 ± 2501 (or in the case without this plus 1
      problem: 123456±25E2) instead of only 1.235E7 for TEST 2?
      I ask because although the error makes the value (the mantissa) inaccurate it
      may still make sense to get this full information printed out that relates to
      the full information that the Real is instantiated with. So a feature to allow
      such kind of output would be great!
      But perhaps this is automatically possible with the new Measure implementation
      for version 3.2 of JScience?

      Sample code:
      public class RealTest {
      public static void main(String[] args) {
      System.out.println("Testing valueOf(LargeInteger mantissa, LargeInteger error,
      int exponent) - TEST 1" );
      System.out.println("-----------------------------------------------------------------------------------------------");

      long mantissa = 1234;
      long error = 1;
      int exponent = 2;

      Real real = Real.valueOf(LargeInteger.valueOf(mantissa),
      LargeInteger.valueOf(error), exponent);

      System.out.println("LargeInteger.valueOf(mantissa): " +
      LargeInteger.valueOf(mantissa));
      System.out.println("LargeInteger.valueOf(error): " + LargeInteger.valueOf(error));
      System.out.println("exponent:" + exponent);
      System.out.println("Real: " + real);
      System.out.println("Real mantissa: " + real.getMantissa());
      System.out.println("Real error: " + real.getError());
      System.out.println("Real exponent: " + real.getExponent());

      Measure measurement = Measure.valueOf(real.toString()+SI.METER);

      System.out.println("Measure: " + measurement);
      System.out.println("-----------------------------------------------------------------------------------------------");

      System.out.println("Testing valueOf(LargeInteger mantissa, LargeInteger error,
      int exponent) - TEST 2 " );
      System.out.println("-----------------------------------------------------------------------------------------------");

      mantissa = 123456;
      error = 25;
      exponent = 2;

      real = Real.valueOf(LargeInteger.valueOf(mantissa), LargeInteger.valueOf(error),
      exponent);

      System.out.println("LargeInteger.valueOf(mantissa): " +
      LargeInteger.valueOf(mantissa));
      System.out.println("LargeInteger.valueOf(error): " + LargeInteger.valueOf(error));
      System.out.println("exponent:" + exponent);
      System.out.println("Real: " + real);
      System.out.println("Real mantissa: " + real.getMantissa());
      System.out.println("Real error: " + real.getError());
      System.out.println("Real exponent: " + real.getExponent());

      measurement = Measure.valueOf(real.toString()+SI.METER);

      System.out.println("Measure: " + measurement);
      System.out.println("-----------------------------------------------------------------------------------------------");

      System.out.println("\nTesting valueOf(java.lang.CharSequence chars) - TEST 3" );
      System.out.println("-----------------------------------------------------------------------------------------------");
      String value = "1234±1E-2";
      System.out.println("String value: " + value);
      real = Real.valueOf(value);

      System.out.println("Real: " + real);
      System.out.println("Real mantissa: " + real.getMantissa());
      System.out.println("Real error: " + real.getError());
      System.out.println("Real exponent: " + real.getExponent());

      measurement = Measure.valueOf(real.toString()+SI.METER);

      System.out.println("Measure: " + measurement);

      System.out.println("-----------------------------------------------------------------------------------------------");

      System.out.println("\nTesting valueOf(java.lang.CharSequence chars) - TEST 4\n
      from
      http://jscience.org/api/org/jscience/mathematics/numbers/Real.html#valueOf(java.lang.CharSequence)"
      );
      System.out.println("-----------------------------------------------------------------------------------------------");
      value = "1.2 ± 0.001";
      System.out.println("String value: " + value);
      real = Real.valueOf(value);

      System.out.println("Real: " + real);
      System.out.println("Real mantissa: " + real.getMantissa());
      System.out.println("Real error: " + real.getError());
      System.out.println("Real exponent: " + real.getExponent());

      measurement = Measure.valueOf(real.toString()+SI.METER);

      System.out.println("Measure: " + measurement);

      System.out.println("-----------------------------------------------------------------------------------------------");

      System.out.println("\nTesting valueOf(java.lang.CharSequence chars) - TEST 5\n
      from
      http://jscience.org/api/org/jscience/mathematics/numbers/Real.html#valueOf(java.lang.CharSequence)"
      );
      System.out.println("-----------------------------------------------------------------------------------------------");
      value = "1200±1E-3";
      System.out.println("String value: " + value);
      real = Real.valueOf(value);

      System.out.println("Real: " + real);
      System.out.println("Real mantissa: " + real.getMantissa());
      System.out.println("Real error: " + real.getError());
      System.out.println("Real exponent: " + real.getExponent());

      measurement = Measure.valueOf(real.toString()+SI.METER);

      System.out.println("Measure: " + measurement);
      System.out.println("-----------------------------------------------------------------------------------------------");
      }
      }

      Output:
      Testing valueOf(LargeInteger mantissa, LargeInteger error, int exponent) - TEST 1
      -----------------------------------------------------------------------------------------------
      LargeInteger.valueOf(mantissa): 1234
      LargeInteger.valueOf(error): 1
      exponent:2
      Real: 1.23E5
      Real mantissa: 123400
      Real error: 101
      Real exponent: 0
      Measure: (123000.0 ± 2.2E-11) m
      -----------------------------------------------------------------------------------------------
      Testing valueOf(LargeInteger mantissa, LargeInteger error, int exponent) - TEST 2
      -----------------------------------------------------------------------------------------------
      LargeInteger.valueOf(mantissa): 123456
      LargeInteger.valueOf(error): 25
      exponent:2
      Real: 1.235E7
      Real mantissa: 12345600
      Real error: 2501
      Real exponent: 0
      Measure: (1.235E7 ± 1.9E-9) m
      -----------------------------------------------------------------------------------------------

      Testing valueOf(java.lang.CharSequence chars) - TEST 3
      -----------------------------------------------------------------------------------------------
      String value: 1234±1E-2
      Real: 0E4
      Real mantissa: 1234000000
      Real error: 123391000001
      Real exponent: -8
      Measure: (0.0 ± 0.0) m
      -----------------------------------------------------------------------------------------------

      Testing valueOf(java.lang.CharSequence chars) - TEST 4
      from
      http://jscience.org/api/org/jscience/mathematics/numbers/Real.html#valueOf(java.lang.CharSequence)
      -----------------------------------------------------------------------------------------------
      String value: 1.2 ± 0.001
      Real: 0E11
      Real mantissa: 919
      Real error: 9188899001
      Real exponent: 0
      Measure: (0.0 ± 0.0) m
      -----------------------------------------------------------------------------------------------

      Testing valueOf(java.lang.CharSequence chars) - TEST 5
      from
      http://jscience.org/api/org/jscience/mathematics/numbers/Real.html#valueOf(java.lang.CharSequence)
      -----------------------------------------------------------------------------------------------
      String value: 1200±1E-3
      Real: 0E3
      Real mantissa: 120000000
      Real error: 11999100001
      Real exponent: -8
      Measure: (0.0 ± 0.0) m
      -----------------------------------------------------------------------------------------------

        Activity

        Hide
        dautelle added a comment -

        Fixed I believe by allowing exact Real number.

        Show
        dautelle added a comment - Fixed I believe by allowing exact Real number.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: