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 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 unit
      S - the return type
      Parameters:
      value - float; the value
      unit - 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 unit
      S - the return type
      Parameters:
      valueSI - float; the SIvalue
      displayUnit - 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 value
      unit - 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 result
      RU - Unit; the relative unit of the parameters and the result
      R - the relative type
      A - the corresponding absolute type
      Parameters:
      left - A, an absolute typed FloatScalar; the left argument
      right - 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 result
      RU - Unit; the relative unit of the parameters and the result
      R - the relative type
      A - the corresponding absolute type
      Parameters:
      left - A, an absolute typed FloatScalar; the left argument
      right - 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 result
      R - the relative type
      Parameters:
      left - R, a relative typed FloatScalar; the left argument
      right - 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 result
      RU - Unit; the relative unit of the parameters and the result
      R - the relative type
      A - the corresponding absolute type
      Parameters:
      left - A, an absolute typed FloatScalar; the left value
      right - 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 result
      R - the relative type
      Parameters:
      left - R, a relative typed FloatScalar; the left value
      right - 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 result
      RU - Unit; the relative unit of the parameters and the result
      R - the relative type
      A - the corresponding absolute type
      Parameters:
      left - A, an absolute typed FloatScalar; value 1
      right - 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 operand
      right - 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 operand
      right - 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 result
      R - the relative type
      Parameters:
      zero - R; the low value
      one - R; the high value
      ratio - float; the ratio between 0 and 1, inclusive
      Returns:
      R; an Absolute Scalar at the ratio between zero and one
    • 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 result
      RU - Unit; the relative unit of the parameters and the result
      R - the relative type
      A - the corresponding absolute type
      Parameters:
      zero - A; the low value
      one - A; the high value
      ratio - float; the ratio between 0 and 1, inclusive
      Returns:
      R; a Relative Scalar at the ratio between zero and one
    • max

      public static <U extends Unit<U>,​ T extends FloatScalarInterface<U,​ T>> T max​(T r1, T r2)
      Return the maximum value of two relative scalars.
      Type Parameters:
      U - Unit; the unit of the parameters and the result
      T - the argument and result type
      Parameters:
      r1 - T; the first scalar
      r2 - 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 result
      T - the argument and result type
      Parameters:
      r1 - T; the first scalar
      r2 - T; the second scalar
      rn - T...; the other scalars
      Returns:
      T; the maximum value of more than two relative scalars
    • min

      public static <U extends Unit<U>,​ T extends FloatScalarInterface<U,​ T>> T min​(T r1, T r2)
      Return the minimum value of two relative scalars.
      Type Parameters:
      U - Unit; the unit of the parameters and the result
      T - the argument and result type
      Parameters:
      r1 - T; the first scalar
      r2 - 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 result
      T - the argument and result type
      Parameters:
      r1 - T; the first scalar
      r2 - T; the second scalar
      rn - T...; the other scalars
      Returns:
      T; the minimum value of more than two relative scalars