From 37e2d9ad2cf5f12e1b445daa8a09d6628842764e Mon Sep 17 00:00:00 2001 From: Dustin <126348160+Dustin4444@users.noreply.github.com> Date: Wed, 26 Mar 2025 05:32:11 -0400 Subject: [PATCH] Add support for non-integer dimensions in Unit API Fixes #256 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/unitsofmeasurement/unit-api/issues/256?shareId=XXXX-XXXX-XXXX-XXXX). --- docs/apidocs/javax/measure/Dimension.html | 6 ++--- docs/apidocs/javax/measure/Unit.html | 28 +++++++++++----------- src/main/java/javax/measure/Dimension.java | 6 ++--- src/main/java/javax/measure/Unit.java | 14 +++++------ 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/docs/apidocs/javax/measure/Dimension.html b/docs/apidocs/javax/measure/Dimension.html index f15a605d..b33465eb 100644 --- a/docs/apidocs/javax/measure/Dimension.html +++ b/docs/apidocs/javax/measure/Dimension.html @@ -189,7 +189,7 @@

divide

  • pow

    -
    Dimension pow(int n)
    +
    Dimension pow(double n)
    Returns this dimension raised to an exponent. (thisn)
    Parameters:
    @@ -202,7 +202,7 @@

    pow

  • root

    -
    Dimension root(int n)
    +
    Dimension root(double n)
    Returns the given root of this dimension.
    Parameters:
    @@ -217,7 +217,7 @@

    root

  • getBaseDimensions

    - +
    Returns the (fundamental) base dimensions and their exponent whose product is this dimension, or null if this dimension is a base dimension.
    diff --git a/docs/apidocs/javax/measure/Unit.html b/docs/apidocs/javax/measure/Unit.html index 3ba042cd..a1255590 100644 --- a/docs/apidocs/javax/measure/Unit.html +++ b/docs/apidocs/javax/measure/Unit.html @@ -176,7 +176,7 @@

    Method Summary

    Returns the quotient of this unit with the one specified.
    -
    Map<? extends Unit<?>,Integer>
    +
    Map<? extends Unit<?>,Double>
    Returns the base units and their exponent whose product is this unit, or null if this unit is a base unit (not a product of existing @@ -243,9 +243,9 @@

    Method Summary

    Returns the product of this unit with the one specified.
    Unit<?>
    -
    pow(int n)
    +
    pow(double n)
    -
    Returns an unit raised to the n-th (integer) power of this unit.
    +
    Returns an unit raised to the n-th power of this unit.
    prefix(Prefix prefix)
    @@ -253,9 +253,9 @@

    Method Summary

    Returns a new unit equal to this unit prefixed by the specified prefix.
    Unit<?>
    -
    root(int n)
    +
    root(double n)
    -
    Returns an unit that is the n-th (integer) root of this unit.
    +
    Returns an unit that is the n-th root of this unit.
    shift(double offset)
    @@ -370,7 +370,7 @@

    getSystemUnit

  • getBaseUnits

    -
    Map<? extends Unit<?>,Integer> getBaseUnits()
    +
    Map<? extends Unit<?>,Double> getBaseUnits()
    Returns the base units and their exponent whose product is this unit, or null if this unit is a base unit (not a product of existing units).
    @@ -702,25 +702,25 @@

    divide

  • -
    +

    root

    -
    Unit<?> root(int n)
    -
    Returns an unit that is the n-th (integer) root of this unit. Equivalent to the mathematical expression unit^(1/n).
    +
    Unit<?> root(double n)
    +
    Returns an unit that is the n-th root of this unit. Equivalent to the mathematical expression unit^(1/n).
    Parameters:
    -
    n - an integer giving the root's order as in 'n-th root'
    +
    n - a double giving the root's order as in 'n-th root'
    Returns:
    the n-th root of this unit.
    Throws:
    -
    ArithmeticException - if n == 0 or if this operation would result in an unit with a fractional exponent.
    +
    ArithmeticException - if n == 0.
  • -
    +

    pow

    -
    Unit<?> pow(int n)
    -
    Returns an unit raised to the n-th (integer) power of this unit. Equivalent to the mathematical expression unit^n.
    +
    Unit<?> pow(double n)
    +
    Returns an unit raised to the n-th power of this unit. Equivalent to the mathematical expression unit^n.
    Parameters:
    n - the exponent.
    diff --git a/src/main/java/javax/measure/Dimension.java b/src/main/java/javax/measure/Dimension.java index c10a4ac5..26acd2d8 100644 --- a/src/main/java/javax/measure/Dimension.java +++ b/src/main/java/javax/measure/Dimension.java @@ -76,7 +76,7 @@ public interface Dimension { * power to raise this {@code Dimension} to. * @return thisn */ - Dimension pow(int n); + Dimension pow(double n); /** * Returns the given root of this dimension. @@ -87,7 +87,7 @@ public interface Dimension { * @throws ArithmeticException * if {@code n == 0}. */ - Dimension root(int n); + Dimension root(double n); /** * Returns the (fundamental) base dimensions and their exponent whose product is this dimension, or {@code null} if this dimension is a base @@ -95,5 +95,5 @@ public interface Dimension { * * @return the mapping between the fundamental dimensions and their exponent. */ - Map getBaseDimensions(); + Map getBaseDimensions(); } diff --git a/src/main/java/javax/measure/Unit.java b/src/main/java/javax/measure/Unit.java index a9d66e8f..7fce5b0b 100644 --- a/src/main/java/javax/measure/Unit.java +++ b/src/main/java/javax/measure/Unit.java @@ -132,7 +132,7 @@ public interface Unit> { * * @return the base units and their exponent making up this unit. */ - Map, Integer> getBaseUnits(); + Map, Double> getBaseUnits(); /** * Indicates if this unit is compatible with the unit specified. Units don't need to be equal to be compatible. For example (assuming {@code ONE} @@ -372,24 +372,24 @@ public interface Unit> { Unit divide(Unit divisor); /** - * Returns an unit that is the n-th (integer) root of this unit. Equivalent to the mathematical expression {@code unit^(1/n)}. + * Returns an unit that is the n-th root of this unit. Equivalent to the mathematical expression {@code unit^(1/n)}. * * @param n - * an integer giving the root's order as in 'n-th root' + * a double giving the root's order as in 'n-th root' * @return the n-th root of this unit. * @throws ArithmeticException - * if {@code n == 0} or if this operation would result in an unit with a fractional exponent. + * if {@code n == 0}. */ - Unit root(int n); + Unit root(double n); /** - * Returns an unit raised to the n-th (integer) power of this unit. Equivalent to the mathematical expression {@code unit^n}. + * Returns an unit raised to the n-th power of this unit. Equivalent to the mathematical expression {@code unit^n}. * * @param n * the exponent. * @return the result of raising this unit to the exponent. */ - Unit pow(int n); + Unit pow(double n); /** * Returns the unit derived from this unit using the specified converter. The converter does not need to be linear. For example: