Class DFastLog

    • Field Summary

      • Fields inherited from class micycle.peasygradients.utilities.fastLog.FastLog

        LN2, LN2F, N
    • Constructor Summary

      Constructors 
      Constructor Description
      DFastLog()
      Create a new natural logarithm calculation instance.
      DFastLog​(double base, int n)
      Create a new logarithm calculation instance.
      DFastLog​(int n)
      Create a new logarithm calculation instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      float fastLog​(double x)
      Calculate the logarithm to the base given in the constructor.
      float fastLog​(float x)
      Calculate the logarithm to the configured base.
      float fastLog2​(double x)
      Calculate the logarithm to base 2.
      float fastLog2​(float x)
      Calculate the logarithm to base 2.
      double getBase()
      Gets the base.
      int getN()
      Gets the number of most significant bits to keep from the mantissa, i.e.
      int getQ()
      Gets the number of least signification bits to ignore from the mantissa of a double (52-bits).
      double getScale()
      Gets the scale to convert from log2 to logB (the base given by FastLog.getBase()) by multiplication.
      float log​(double x)
      Calculate the logarithm to the configured base, handling special cases.
      float log​(float x)
      Calculate the logarithm to the configured base, handling special cases.
      float log2​(double x)
      Calculate the logarithm to base 2, handling special cases.
      float log2​(float x)
      Calculate the logarithm to base 2, handling special cases.
    • Constructor Detail

      • DFastLog

        public DFastLog()
        Create a new natural logarithm calculation instance.
      • DFastLog

        public DFastLog​(int n)
        Create a new logarithm calculation instance. This will hold the pre-calculated log values for base E and a table size depending on a given mantissa quantization.
        Parameters:
        n - The number of bits to keep from the mantissa. Table storage = 2^(n+1) * 4 bytes, e.g. 64Kb for n=13
      • DFastLog

        public DFastLog​(double base,
                        int n)
        Create a new logarithm calculation instance. This will hold the pre-calculated log values for a given base and a table size depending on a given mantissa quantization.
        Parameters:
        base - the logarithm base (e.g. 2 for log duals, 10 for decibels calculations, Math.E for natural log)
        n - The number of bits to keep from the mantissa. Table storage = 2^(n+1) * 4 bytes, e.g. 64Kb for n=13
    • Method Detail

      • getBase

        public double getBase()
        Description copied from class: FastLog
        Gets the base.
        Specified by:
        getBase in class FastLog
        Returns:
        the base
      • getScale

        public double getScale()
        Description copied from class: FastLog
        Gets the scale to convert from log2 to logB (the base given by FastLog.getBase()) by multiplication.
        Specified by:
        getScale in class FastLog
        Returns:
        the scale
      • getN

        public int getN()
        Description copied from class: FastLog
        Gets the number of most significant bits to keep from the mantissa, i.e. the binary precision of the floating point number before computing the log.
        Specified by:
        getN in class FastLog
        Returns:
        the number of most significant bits to keep
      • getQ

        public int getQ()
        Gets the number of least signification bits to ignore from the mantissa of a double (52-bits).
        Returns:
        the number of least signification bits to ignore
      • log2

        public float log2​(double x)
        Description copied from class: FastLog
        Calculate the logarithm to base 2, handling special cases.

        Special cases:

        • If the argument is NaN or less than zero, then the result is NaN.
        • If the argument is positive infinity, then the result is positive infinity.
        • If the argument is positive zero or negative zero, then the result is negative infinity.
        Specified by:
        log2 in class FastLog
        Parameters:
        x - the argument
        Returns:
        log(x)
      • log2

        public float log2​(float x)
        Calculate the logarithm to base 2, handling special cases.

        Special cases:

        • If the argument is NaN or less than zero, then the result is NaN.
        • If the argument is positive infinity, then the result is positive infinity.
        • If the argument is positive zero or negative zero, then the result is negative infinity.

        This just calls log2(double). Use FFastLog for a dedicated float version.

        Specified by:
        log2 in class FastLog
        Parameters:
        x - the argument
        Returns:
        log(x)
      • fastLog2

        public float fastLog2​(double x)
        Calculate the logarithm to base 2. Requires the argument be finite and positive.

        Special cases:

        • If the argument is NaN, then the result is incorrect.
        • If the argument is negative, then the result is incorrect (log(-x)).
        • If the argument is positive infinity, then the result is incorrect (Math.log(Double.MAX_VALUE)).
        • If the argument is positive zero or negative zero, then the result is negative infinity.
        Specified by:
        fastLog2 in class FastLog
        Parameters:
        x - the argument (must be strictly positive)
        Returns:
        log( x )
      • fastLog2

        public float fastLog2​(float x)
        Calculate the logarithm to base 2. Requires the argument be finite and strictly positive.

        Special cases:

        • If the argument is NaN, then the result is incorrect.
        • If the argument is negative, then the result is incorrect.
        • If the argument is positive infinity, then the result is incorrect.
        • If the argument is positive zero or negative zero, then the result is incorrect.

        Sub-classes may handle some of the special cases.

        This just calls fastLog2(double). Use FFastLog for a dedicated float version.

        Specified by:
        fastLog2 in class FastLog
        Parameters:
        x - the argument (must be strictly positive)
        Returns:
        log(x)
      • log

        public float log​(double x)
        Description copied from class: FastLog
        Calculate the logarithm to the configured base, handling special cases.

        Special cases:

        • If the argument is NaN or less than zero, then the result is NaN.
        • If the argument is positive infinity, then the result is positive infinity.
        • If the argument is positive zero or negative zero, then the result is negative infinity.
        Specified by:
        log in class FastLog
        Parameters:
        x - the argument
        Returns:
        log(x)
        See Also:
        FastLog.getBase()
      • log

        public float log​(float x)
        Calculate the logarithm to the configured base, handling special cases.

        Special cases:

        • If the argument is NaN or less than zero, then the result is NaN.
        • If the argument is positive infinity, then the result is positive infinity.
        • If the argument is positive zero or negative zero, then the result is negative infinity.

        This just calls log(double). Use FFastLog for a dedicated float version.

        Specified by:
        log in class FastLog
        Parameters:
        x - the argument
        Returns:
        log(x)
        See Also:
        FastLog.getBase()
      • fastLog

        public float fastLog​(double x)
        Calculate the logarithm to the base given in the constructor. Requires the argument be finite and positive.

        Special cases:

        • If the argument is NaN, then the result is incorrect.
        • If the argument is negative, then the result is incorrect (log(-x)).
        • If the argument is positive infinity, then the result is incorrect (Math.log(Double.MAX_VALUE)).
        • If the argument is positive zero or negative zero, then the result is negative infinity.
        Specified by:
        fastLog in class FastLog
        Parameters:
        x - the argument (must be strictly positive)
        Returns:
        log( x )
        See Also:
        FastLog.getBase()
      • fastLog

        public float fastLog​(float x)
        Calculate the logarithm to the configured base. Requires the argument be finite and strictly positive.

        Special cases:

        • If the argument is NaN, then the result is incorrect.
        • If the argument is negative, then the result is incorrect.
        • If the argument is positive infinity, then the result is incorrect.
        • If the argument is positive zero or negative zero, then the result is incorrect.

        Sub-classes may handle some of the special cases.

        This just calls fastLog(double). Use FFastLog for a dedicated float version.

        Specified by:
        fastLog in class FastLog
        Parameters:
        x - the argument (must be strictly positive)
        Returns:
        log(x)
        See Also:
        FastLog.getBase()