Class DoubleScalar
java.lang.Object
org.djunits.value.vdouble.scalar.base.DoubleScalar
public abstract class DoubleScalar extends Object
Static methods to create and operate on DoubleScalars.
Copyright (c) 2015-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.
- Author:
- Alexander Verbraeck, Peter Knoppers
-
Method Summary
Modifier and Type Method Description static SIScalardivide(DoubleScalarInterface.Rel<?,?> left, DoubleScalarInterface.Rel<?,?> right)Divide two values; the result is a new instance with a different (existing or generated) SI unit.static <U extends Unit<U>, S extends DoubleScalarInterface<U, S>>
Sinstantiate(double value, U unit)Instantiate the DoubleScalar based on its unit.static <S extends DoubleScalarInterface<?, S>>
SinstantiateAnonymous(double value, Unit<?> unit)Instantiate the DoubleScalar based on its unit.static <U extends Unit<U>, S extends DoubleScalarInterface<U, S>>
SinstantiateSI(double valueSI, U displayUnit)Instantiate the DoubleScalar with an SI value and add the displayUnit later.static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends DoubleScalarInterface.RelWithAbs<AU, A, RU, R>, A extends DoubleScalarInterface.Abs<AU, A, RU, R>>
Ainterpolate(A zero, A one, double ratio)Interpolate between two values.static <U extends Unit<U>, R extends DoubleScalarInterface.Rel<U, R>>
Rinterpolate(R zero, R one, double ratio)Interpolate between two values.static <U extends Unit<U>, T extends DoubleScalarInterface<U, T>>
Tmax(T r1, T r2)Return the maximum value of two relative scalars.static <U extends Unit<U>, T extends DoubleScalarInterface<U, T>>
Tmax(T r1, T r2, T... rn)Return the maximum value of more than two relative scalars.static <U extends Unit<U>, T extends DoubleScalarInterface<U, T>>
Tmin(T r1, T r2)Return the minimum value of two relative scalars.static <U extends Unit<U>, T extends DoubleScalarInterface<U, T>>
Tmin(T r1, T r2, T... rn)Return the minimum value of more than two relative scalars.static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends DoubleScalarInterface.RelWithAbs<AU, A, RU, R>, A extends DoubleScalarInterface.Abs<AU, A, RU, R>>
Rminus(A left, A right)Subtract two absolute values.static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends DoubleScalarInterface.RelWithAbs<AU, A, RU, R>, A extends DoubleScalarInterface.Abs<AU, A, RU, R>>
Aminus(A left, R right)Subtract a Relative value from an absolute value.static <U extends Unit<U>, R extends DoubleScalarInterface.Rel<U, R>>
Rminus(R left, R right)Subtract a relative value from a relative value.static SIScalarmultiply(DoubleScalarInterface.Rel<?,?> left, DoubleScalarInterface.Rel<?,?> right)Multiply two values; the result is a new instance with a different (existing or generated) SI unit.static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends DoubleScalarInterface.RelWithAbs<AU, A, RU, R>, A extends DoubleScalarInterface.Abs<AU, A, RU, R>>
Aplus(A left, R right)Add a Relative value to an Absolute value.static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends DoubleScalarInterface.RelWithAbs<AU, A, RU, R>, A extends DoubleScalarInterface.Abs<AU, A, RU, R>>
Aplus(R left, A right)Add an Absolute value to a Relative value.static <U extends Unit<U>, R extends DoubleScalarInterface.Rel<U, R>>
Rplus(R left, R right)Add a Relative value to a Relative value.
-
Method Details
-
instantiate
public static <U extends Unit<U>, S extends DoubleScalarInterface<U, S>> S instantiate(double value, U unit)Instantiate the DoubleScalar based on its unit. Rigid check on types by the compiler.- Type Parameters:
U- the unitS- the return type- Parameters:
value- double; the valueunit- U; the unit in which the value is expressed- Returns:
- S; an instantiated DoubleScalar with the value expressed in the unit
-
instantiateSI
public static <U extends Unit<U>, S extends DoubleScalarInterface<U, S>> S instantiateSI(double valueSI, U displayUnit)Instantiate the DoubleScalar with an SI value and add the displayUnit later. Rigid check on types by the compiler.- Type Parameters:
U- the unitS- the return type- Parameters:
valueSI- double; the SIvaluedisplayUnit- U; the unit in which the value will be displayed- Returns:
- S; an instantiated DoubleScalar with the SI value and the display unit
-
instantiateAnonymous
public static <S extends DoubleScalarInterface<?, S>> S instantiateAnonymous(double value, Unit<?> unit)Instantiate the DoubleScalar based on its unit. Loose check for types on the compiler. This allows the unit to be specified as a Unit<?> type.
Note that it is possible to make mistakes with anonymous units.- Type Parameters:
S- the return type- Parameters:
value- double; the valueunit- Unit<?>; the unit in which the value is expressed- Returns:
- S; an instantiated DoubleScalar with the value expressed in the unit
-
plus
public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends DoubleScalarInterface.RelWithAbs<AU, A, RU, R>, A extends DoubleScalarInterface.Abs<AU, A, RU, R>> A plus(A left, R right)Add a Relative value to an Absolute value. Return a new instance of the value. The unit of the return value will be the unit of the left argument.- Type Parameters:
AU- Unit; the absolute unit of the parameters and the resultRU- Unit; the relative unit of the parameters and the resultR- the relative typeA- the corresponding absolute type- Parameters:
left- A, an absolute typed DoubleScalar; the left argumentright- R, a relative typed DoubleScalar; the right argument- Returns:
- A; an absolute typed DoubleScalar; the sum of the values as an Absolute value
-
plus
public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends DoubleScalarInterface.RelWithAbs<AU, A, RU, R>, A extends DoubleScalarInterface.Abs<AU, A, RU, R>> A plus(R left, A right)Add an Absolute value to a Relative value. Return a new instance of the value. The unit of the return value will be the unit of the left argument.- Type Parameters:
AU- Unit; the absolute unit of the parameters and the resultRU- Unit; the relative unit of the parameters and the resultR- the relative typeA- the corresponding absolute type- Parameters:
left- A, an absolute typed DoubleScalar; the left argumentright- R, a relative typed DoubleScalar; the right argument- Returns:
- A; an absolute typed DoubleScalar; the sum of the values as an Absolute value
-
plus
public static <U extends Unit<U>, R extends DoubleScalarInterface.Rel<U, R>> R plus(R left, R right)Add a Relative value to a Relative value. Return a new instance of the value. The unit of the return value will be the unit of the left argument.- Type Parameters:
U- Unit; the unit of the parameters and the resultR- the relative type- Parameters:
left- R, a relative typed DoubleScalar; the left argumentright- R, a relative typed DoubleScalar; the right argument- Returns:
- R; a relative typed DoubleScalar; the sum of the values as a Relative value
-
minus
public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends DoubleScalarInterface.RelWithAbs<AU, A, RU, R>, A extends DoubleScalarInterface.Abs<AU, A, RU, R>> A minus(A left, R right)Subtract a Relative value from an absolute value. Return a new instance of the value. The unit of the return value will be the unit of the left argument.- Type Parameters:
AU- Unit; the absolute unit of the parameters and the resultRU- Unit; the relative unit of the parameters and the resultR- the relative typeA- the corresponding absolute type- Parameters:
left- A, an absolute typed DoubleScalar; the left valueright- R, a relative typed DoubleScalar; the right value- Returns:
- A; an absolute typed DoubleScalar; the resulting value as an absolute value
-
minus
public static <U extends Unit<U>, R extends DoubleScalarInterface.Rel<U, R>> R minus(R left, R right)Subtract a relative value from a relative value. Return a new instance of the value. The unit of the value will be the unit of the first argument.- Type Parameters:
U- Unit; the unit of the parameters and the resultR- the relative type- Parameters:
left- R, a relative typed DoubleScalar; the left valueright- R, a relative typed DoubleScalar; the right value- Returns:
- R; a relative typed DoubleScalar; the resulting value as a relative value
-
minus
public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends DoubleScalarInterface.RelWithAbs<AU, A, RU, R>, A extends DoubleScalarInterface.Abs<AU, A, RU, R>> R minus(A left, A right)Subtract two absolute values. Return a new instance of a relative value of the difference. The unit of the value will be the unit of the first argument.- Type Parameters:
AU- Unit; the absolute unit of the parameters and the resultRU- Unit; the relative unit of the parameters and the resultR- the relative typeA- the corresponding absolute type- Parameters:
left- A, an absolute typed DoubleScalar; value 1right- A, an absolute typed DoubleScalar; value 2- Returns:
- R; a relative typed DoubleScalar; the difference of the two absolute values as a relative value
-
multiply
public static SIScalar multiply(DoubleScalarInterface.Rel<?,?> left, DoubleScalarInterface.Rel<?,?> right)Multiply two values; the result is a new instance with a different (existing or generated) SI unit.- Parameters:
left- DoubleScalarInterface.Rel<?, ?>; the left operandright- DoubleScalarInterface.Rel<?, ?>; the right operand- Returns:
- DoubleScalar.Rel<SIUnit>; the product of the two values
-
divide
public static SIScalar divide(DoubleScalarInterface.Rel<?,?> left, DoubleScalarInterface.Rel<?,?> right)Divide two values; the result is a new instance with a different (existing or generated) SI unit.- Parameters:
left- DoubleScalarInterface.Rel<?, ?>; the left operandright- DoubleScalarInterface.Rel<?, ?>; the right operand- Returns:
- DoubleScalar.Rel<SIUnit>; the ratio of the two values
-
interpolate
public static <U extends Unit<U>, R extends DoubleScalarInterface.Rel<U, R>> R interpolate(R zero, R one, double ratio)Interpolate between two values. Made to be able to call e.g., Area a = DoubleScalar.interpolate(a1, a2, 0.4);- Type Parameters:
U- Unit; the unit of the parameters and the resultR- the relative type- Parameters:
zero- R; the low valueone- R; the high valueratio- double; the ratio between 0 and 1, inclusive- Returns:
- R; an Absolute Scalar at the
ratiobetweenzeroandone
-
interpolate
public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends DoubleScalarInterface.RelWithAbs<AU, A, RU, R>, A extends DoubleScalarInterface.Abs<AU, A, RU, R>> A interpolate(A zero, A one, double ratio)Interpolate between two values. Made to be able to call e.g., Time t = DoubleScalar.interpolate(t1, t2, 0.4);- Type Parameters:
AU- Unit; the absolute unit of the parameters and the resultRU- Unit; the relative unit of the parameters and the resultR- the relative typeA- the corresponding absolute type- Parameters:
zero- A; the low valueone- A; the high valueratio- double; the ratio between 0 and 1, inclusive- Returns:
- R; a Relative Scalar at the
ratiobetweenzeroandone
-
max
Return the maximum value of two relative scalars.- Type Parameters:
U- Unit; the unit of the parameters and the resultT- the argument and result type- Parameters:
r1- T; the first scalarr2- T; the second scalar- Returns:
- T; the maximum value of two relative scalars
-
max
@SafeVarargs public static <U extends Unit<U>, T extends DoubleScalarInterface<U, T>> T max(T r1, T r2, T... rn)Return the maximum value of more than two relative scalars.- Type Parameters:
U- Unit; the unit of the parameters and the resultT- the argument and result type- Parameters:
r1- T; the first scalarr2- T; the second scalarrn- T...; the other scalars- Returns:
- T; the maximum value of more than two relative scalars
-
min
Return the minimum value of two relative scalars.- Type Parameters:
U- Unit; the unit of the parameters and the resultT- the argument and result type- Parameters:
r1- T; the first scalarr2- T; the second scalar- Returns:
- T; the minimum value of two relative scalars
-
min
@SafeVarargs public static <U extends Unit<U>, T extends DoubleScalarInterface<U, T>> T min(T r1, T r2, T... rn)Return the minimum value of more than two relative scalars.- Type Parameters:
U- Unit; the unit of the parameters and the resultT- the argument and result type- Parameters:
r1- T; the first scalarr2- T; the second scalarrn- T...; the other scalars- Returns:
- T; the minimum value of more than two relative scalars
-