Class FloatScalar
java.lang.Object
org.djunits.value.vfloat.scalar.base.FloatScalar
public abstract class FloatScalar extends Object
Static methods to create and operate on FloatScalars.
Copyright (c) 2015-2019 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 FloatSIScalar
divide(FloatScalarInterface.Rel<?,?> left, FloatScalarInterface.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 FloatScalarInterface<U, S>>
Sinstantiate(float value, U unit)
Instantiate the FloatScalar based on its unit.static <S extends FloatScalarInterface<?, S>>
SinstantiateAnonymous(float value, Unit<?> unit)
Instantiate the FloatScalar based on its unit.static <U extends Unit<U>, S extends FloatScalarInterface<U, S>>
SinstantiateSI(float valueSI, U displayUnit)
Instantiate the FloatScalar with an SI value and add the displayUnit later.static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends FloatScalarInterface.RelWithAbs<AU, A, RU, R>, A extends FloatScalarInterface.Abs<AU, A, RU, R>>
Ainterpolate(A zero, A one, float ratio)
Interpolate between two values.static <U extends Unit<U>, R extends FloatScalarInterface.Rel<U, R>>
Rinterpolate(R zero, R one, float ratio)
Interpolate between two values.static <U extends Unit<U>, T extends FloatScalarInterface<U, T>>
Tmax(T r1, T r2)
Return the maximum value of two relative scalars.static <U extends Unit<U>, T extends FloatScalarInterface<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 FloatScalarInterface<U, T>>
Tmin(T r1, T r2)
Return the minimum value of two relative scalars.static <U extends Unit<U>, T extends FloatScalarInterface<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 FloatScalarInterface.RelWithAbs<AU, A, RU, R>, A extends FloatScalarInterface.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 FloatScalarInterface.RelWithAbs<AU, A, RU, R>, A extends FloatScalarInterface.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 FloatScalarInterface.Rel<U, R>>
Rminus(R left, R right)
Subtract a relative value from a relative value.static FloatSIScalar
multiply(FloatScalarInterface.Rel<?,?> left, FloatScalarInterface.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 FloatScalarInterface.RelWithAbs<AU, A, RU, R>, A extends FloatScalarInterface.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 FloatScalarInterface.RelWithAbs<AU, A, RU, R>, A extends FloatScalarInterface.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 FloatScalarInterface.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 FloatScalarInterface<U, S>> S instantiate(float value, U unit)Instantiate the FloatScalar based on its unit. Rigid check on types by the compiler.- Type Parameters:
U
- the unitS
- the return type- Parameters:
value
- float; the valueunit
- U; the unit in which the value is expressed- Returns:
- S; an instantiated FloatScalar with the value expressed in the unit
-
instantiateSI
public static <U extends Unit<U>, S extends FloatScalarInterface<U, S>> S instantiateSI(float valueSI, U displayUnit)Instantiate the FloatScalar 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
- float; the SIvaluedisplayUnit
- U; the unit in which the value will be displayed- Returns:
- S; an instantiated FloatScalar with the SI value and the display unit
-
instantiateAnonymous
public static <S extends FloatScalarInterface<?, S>> S instantiateAnonymous(float value, Unit<?> unit)Instantiate the FloatScalar 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
- float; the valueunit
- Unit<?>; the unit in which the value is expressed- Returns:
- S; an instantiated FloatScalar with the value expressed in the unit
-
plus
public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends FloatScalarInterface.RelWithAbs<AU, A, RU, R>, A extends FloatScalarInterface.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 FloatScalar; the left argumentright
- R, a relative typed FloatScalar; the right argument- Returns:
- A; an absolute typed FloatScalar; the sum of the values as an Absolute value
-
plus
public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends FloatScalarInterface.RelWithAbs<AU, A, RU, R>, A extends FloatScalarInterface.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 FloatScalar; the left argumentright
- R, a relative typed FloatScalar; the right argument- Returns:
- A; an absolute typed FloatScalar; the sum of the values as an Absolute value
-
plus
public static <U extends Unit<U>, R extends FloatScalarInterface.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 FloatScalar; the left argumentright
- R, a relative typed FloatScalar; the right argument- Returns:
- R; a relative typed FloatScalar; the sum of the values as a Relative value
-
minus
public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends FloatScalarInterface.RelWithAbs<AU, A, RU, R>, A extends FloatScalarInterface.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 FloatScalar; the left valueright
- R, a relative typed FloatScalar; the right value- Returns:
- A; an absolute typed FloatScalar; the resulting value as an absolute value
-
minus
public static <U extends Unit<U>, R extends FloatScalarInterface.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 FloatScalar; the left valueright
- R, a relative typed FloatScalar; the right value- Returns:
- R; a relative typed FloatScalar; the resulting value as a relative value
-
minus
public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends FloatScalarInterface.RelWithAbs<AU, A, RU, R>, A extends FloatScalarInterface.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 FloatScalar; value 1right
- A, an absolute typed FloatScalar; value 2- Returns:
- R; a relative typed FloatScalar; the difference of the two absolute values as a relative value
-
multiply
public static FloatSIScalar multiply(FloatScalarInterface.Rel<?,?> left, FloatScalarInterface.Rel<?,?> right)Multiply two values; the result is a new instance with a different (existing or generated) SI unit.- Parameters:
left
- FloatScalarInterfaceRel<?, ?>; the left operandright
- FloatScalarInterfaceRel<?, ?>; the right operand- Returns:
- FloatScalar.Rel<SIUnit>; the product of the two values
-
divide
public static FloatSIScalar divide(FloatScalarInterface.Rel<?,?> left, FloatScalarInterface.Rel<?,?> right)Divide two values; the result is a new instance with a different (existing or generated) SI unit.- Parameters:
left
- FloatScalarInterfaceRel<?, ?>; the left operandright
- FloatScalarInterfaceRel<?, ?>; the right operand- Returns:
- FloatScalar.Rel<SIUnit>; the ratio of the two values
-
interpolate
public static <U extends Unit<U>, R extends FloatScalarInterface.Rel<U, R>> R interpolate(R zero, R one, float ratio)Interpolate between two values. Made to be able to call e.g., Area a = FloatScalar.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
- float; the ratio between 0 and 1, inclusive- Returns:
- R; an Absolute Scalar at the
ratio
betweenzero
andone
-
interpolate
public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends FloatScalarInterface.RelWithAbs<AU, A, RU, R>, A extends FloatScalarInterface.Abs<AU, A, RU, R>> A interpolate(A zero, A one, float ratio)Interpolate between two values. Made to be able to call e.g., Time t = FloatScalar.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
- float; the ratio between 0 and 1, inclusive- Returns:
- R; a Relative Scalar at the
ratio
betweenzero
andone
-
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 FloatScalarInterface<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 FloatScalarInterface<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
-