jscience
  1. jscience
  2. JSCIENCE-3

Quantity.to(NonSI.DEGREE_ANGLE) returns Dimensionless instead of Angle

    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:
      3

      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

      When I use the Quantity method, to(NonSI.DEGREE_ANGLE), the quantity
      returned comes back as Dimensionless instead of Angle, which is what
      one would expect.

      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 -

        The problem is due to the current rather simplistic unit-quantity mapping.

        When searching for the appropriate quantity class, the following happens:

        1 - Search for quantity directly mapped to the unit.

        2 - Search for quantity mapped to the unit.getBaseUnits(),

        3 - If none returns a general quantity.

        For NonSI.DEGREE the base units is Unit.ONE and a dimensionless quantity is
        returned.

        Solution:

        The Unit class should provide a Unit.getParentUnit(), then identifying the
        quantity class could be:

        1 - Search for quantity class directly associated to the quantity unit.

        2 - Search for the quantity class associated to any of the parent units.

        3 - If none returns a general quantity.

        The parent unit of NonSI.DEGREE_ANGLE is SI.RADIAN associated to the Angle class.

        Show
        dautelle added a comment - The problem is due to the current rather simplistic unit-quantity mapping. When searching for the appropriate quantity class, the following happens: 1 - Search for quantity directly mapped to the unit. 2 - Search for quantity mapped to the unit.getBaseUnits(), 3 - If none returns a general quantity. For NonSI.DEGREE the base units is Unit.ONE and a dimensionless quantity is returned. Solution: The Unit class should provide a Unit.getParentUnit(), then identifying the quantity class could be: 1 - Search for quantity class directly associated to the quantity unit. 2 - Search for the quantity class associated to any of the parent units. 3 - If none returns a general quantity. The parent unit of NonSI.DEGREE_ANGLE is SI.RADIAN associated to the Angle class.
        Hide
        dautelle added a comment -

        Fixed in 2.0 Beta2

        Show
        dautelle added a comment - Fixed in 2.0 Beta2

          People

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

            Dates

            • Created:
              Updated:
              Resolved: