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 @@
(thisn)null if this dimension is a base
dimension.null if this unit is a base unit (not a product of existing
@@ -243,9 +243,9 @@ Unit<?>pow(int n) pow(double n) prefix.Unit<?>root(int n) root(double n) shift(double offset) null if this unit is a base unit (not a product of existing
units).unit^(1/n).unit^(1/n).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'ArithmeticException - if n == 0 or if this operation would result in an unit with a fractional exponent.ArithmeticException - if n == 0.unit^n.unit^n.n - the exponent.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 extends Dimension, Integer> getBaseDimensions();
+ Map extends Dimension, Double> 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 extends Unit>, Integer> getBaseUnits(); + Map extends Unit>, 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: