jscience
  1. jscience
  2. JSCIENCE-2

Quantities with negative bounds, taken to integer power returns NaN

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • 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:
      2

      Description

      The code at the end of this message produces the following output:

      acos1d[class org.jscience.physics.quantities.Dimensionless]: 0 °
      acos1 min: -1.490116119384766E-8
      acos1 max: 1.490116119384766E-8
      scos1: 0
      acos1 min: -1.4901161193847663E-8
      acos1 max: 1.4901161193847663E-8
      scos1sq[class org.jscience.physics.quantities.Dimensionless]: NaN
      scos1sq min: NaN
      scos1sq max: 2.220446049250319E-16

      I think that because javolution.lang.MathLib defines pow(double,double) as:
      public static double pow(double x, double y)

      { return MathLib.exp(y * MathLib.log(x)); }

      you get NaN when you try to take a power where the bounds of the
      quantity go negative, because you can't take a log of a negative
      number. The power function should still be defined for any integer exponent,
      though.

      Dale

      import static org.jscience.physics.units.NonSI.DEGREE_ANGLE;

      import org.jscience.physics.quantities.Angle;
      import org.jscience.physics.quantities.Dimensionless;
      import org.jscience.physics.quantities.Quantity;

      public final class PowerTest {
      public static void main(String[] args)

      { final Angle acos1=Dimensionless.ONE.acos(); final Quantity acos1d=acos1.to(DEGREE_ANGLE); System.out.println("acos1d["+acos1d.getClass()+"]: "+acos1d); System.out.println("acos1 min: "+acos1.getMinimum()); System.out.println("acos1 max: "+acos1.getMaximum()); final Dimensionless scos1=acos1.sine(); System.out.println("scos1: "+scos1); System.out.println("acos1 min: "+scos1.getMinimum()); System.out.println("acos1 max: "+scos1.getMaximum()); final Quantity scos1sq=scos1.pow(2); System.out.println("scos1sq["+scos1sq.getClass()+"]: "+scos1sq); System.out.println("scos1sq min: "+scos1sq.getMinimum()); System.out.println("scos1sq max: "+scos1sq.getMaximum()); }

      }

        Activity

        Hide
        dautelle added a comment -

        Indeed the Number.pow(int) should not have been overriden.
        The problem has been fixed by removing Quantity.pow(int)
        Fixed in 2.0.0

        Show
        dautelle added a comment - Indeed the Number.pow(int) should not have been overriden. The problem has been fixed by removing Quantity.pow(int) Fixed in 2.0.0

          People

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

            Dates

            • Created:
              Updated:
              Resolved: