Class FastLog
- java.lang.Object
-
- micycle.peasygradients.utilities.fastLog.FastLog
-
-
Constructor Summary
Constructors Constructor Description FastLog()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static double
computeScale(double base)
Computes the scale to convert from log2 to logB (using the given base) by multiplication.static double
exactLog2(double val)
Calculate the logarithm with base 2.abstract float
fastLog(double x)
Calculate the logarithm to the configured base.abstract float
fastLog(float x)
Calculate the logarithm to the configured base.abstract float
fastLog2(double x)
Calculate the logarithm to base 2.abstract float
fastLog2(float x)
Calculate the logarithm to base 2.double
fastLog2D(double x)
Calculate the logarithm to base 2.double
fastLogD(double x)
Calculate the logarithm to the configured base.abstract double
getBase()
Gets the base.abstract int
getN()
Gets the number of most significant bits to keep from the mantissa, i.e.abstract double
getScale()
Gets the scale to convert from log2 to logB (the base given bygetBase()
) by multiplication.abstract float
log(double x)
Calculate the logarithm to the configured base, handling special cases.abstract float
log(float x)
Calculate the logarithm to the configured base, handling special cases.abstract float
log2(double x)
Calculate the logarithm to base 2, handling special cases.abstract float
log2(float x)
Calculate the logarithm to base 2, handling special cases.double
log2D(double x)
Calculate the logarithm to base 2, handling special cases.double
logD(double x)
Calculate the logarithm to the configured base, handling special cases.
-
-
-
Field Detail
-
LN2
public static final double LN2
Natural logarithm of 2.
-
LN2F
public static final float LN2F
Natural logarithm of 2.
-
N
public static final int N
The default value for n (the number of bits to keep from the mantissa).- See Also:
- Constant Field Values
-
-
Method Detail
-
computeScale
public static double computeScale(double base)
Computes the scale to convert from log2 to logB (using the given base) by multiplication.scale = Math.log(2) / Math.log(base)
- Parameters:
base
- the base- Returns:
- the scale
-
exactLog2
public static double exactLog2(double val)
Calculate the logarithm with base 2.return Math.log(val) / Math.log(2)
- Parameters:
val
- the input value- Returns:
- the log2 of the value
-
getBase
public abstract double getBase()
Gets the base.- Returns:
- the base
-
getScale
public abstract double getScale()
Gets the scale to convert from log2 to logB (the base given bygetBase()
) by multiplication.- Returns:
- the scale
-
getN
public abstract int getN()
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.- Returns:
- the number of most significant bits to keep
-
log2
public abstract 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.
- Parameters:
x
- the argument- Returns:
- log(x)
-
log2
public abstract float log2(double 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.
- Parameters:
x
- the argument- Returns:
- log(x)
-
fastLog2
public abstract 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.
- Parameters:
x
- the argument (must be strictly positive)- Returns:
- log(x)
-
fastLog2
public abstract float fastLog2(double 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.
- Parameters:
x
- the argument (must be strictly positive)- Returns:
- log(x)
-
log
public abstract 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.
- Parameters:
x
- the argument- Returns:
- log(x)
- See Also:
getBase()
-
log
public abstract float log(double 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.
- Parameters:
x
- the argument- Returns:
- log(x)
- See Also:
getBase()
-
fastLog
public abstract 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.
- Parameters:
x
- the argument (must be strictly positive)- Returns:
- log(x)
- See Also:
getBase()
-
fastLog
public abstract float fastLog(double 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.
- Parameters:
x
- the argument (must be strictly positive)- Returns:
- log(x)
- See Also:
getBase()
-
log2D
public double log2D(double 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 can be re-implemented if
fastLog(double)
can be returned in double precision.- Parameters:
x
- the argument- Returns:
- log(x)
-
fastLog2D
public double fastLog2D(double 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 can be re-implemented if
fastLog(double)
can be returned in double precision.- Parameters:
x
- the argument (must be strictly positive)- Returns:
- log(x)
-
logD
public double logD(double 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 can be re-implemented if
log(double)
can be returned in double precision.- Parameters:
x
- the argument- Returns:
- log(x)
- See Also:
getBase()
-
fastLogD
public double fastLogD(double 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 can be re-implemented if
fastLog(double)
can be returned in double precision.- Parameters:
x
- the argument (must be strictly positive)- Returns:
- log(x)
- See Also:
getBase()
-
-