Class DoubleScalar


  • public abstract class DoubleScalar
    extends Object
    Static methods to create and operate on DoubleScalars.

    Copyright (c) 2015-2023 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 Detail

      • 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 unit
        S - the return type
        Parameters:
        value - double; the value
        unit - 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 unit
        S - the return type
        Parameters:
        valueSI - double; the SIvalue
        displayUnit - 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 value
        unit - 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 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 DoubleScalar; the left argument
        right - 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 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 DoubleScalar; the left argument
        right - 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 result
        R - the relative type
        Parameters:
        left - R, a relative typed DoubleScalar; the left argument
        right - 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 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 DoubleScalar; the left value
        right - 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 result
        R - the relative type
        Parameters:
        left - R, a relative typed DoubleScalar; the left value
        right - 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 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 DoubleScalar; value 1
        right - 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 operand
        right - 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 operand
        right - 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 result
        R - the relative type
        Parameters:
        zero - R; the low value
        one - R; the high value
        ratio - double; 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 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 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 - double; 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 DoubleScalarInterface<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 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 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 DoubleScalarInterface<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 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 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