[wpiunits] Add absolute value and copy sign functionality (#7358)

This commit is contained in:
Vignesh Balasubramaniam
2024-11-18 19:46:15 -06:00
committed by GitHub
parent 57e10755fd
commit ac1836ec44

View File

@@ -98,6 +98,27 @@ public interface Measure<U extends Unit> extends Comparable<Measure<U>> {
return (U) unit().getBaseUnit();
}
/**
* Absolute value of measure.
*
* @param unit unit to use
* @return the absolute value of this measure in the given unit
*/
default double abs(U unit) {
return Math.abs(this.in(unit));
}
/**
* Take the sign of another measure.
*
* @param other measure from which to take sign
* @param unit unit to use
* @return the value of the measure in the given unit with the sign of the provided measure
*/
default double copySign(Measure<U> other, U unit) {
return Math.copySign(this.in(unit), other.in(unit));
}
/**
* Returns an immutable copy of this measure. The copy can be used freely and is guaranteed never
* to change.