Class FFastLog
- java.lang.Object
-
- micycle.peasygradients.utilities.fastLog.FastLog
-
- micycle.peasygradients.utilities.fastLog.FFastLog
-
public class FFastLog extends FastLog
Implementation of the ICSILog algorithm as described in O. Vinyals, G. Friedland, N. Mirghafori "Revisiting a basic function on current CPUs: A fast logarithm implementation with adjustable accuracy" (2007).This class is based on the original algorithm description and a Java implementation by Hanns Holger Rutz.
-
-
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 base given in the constructor.float
fastLog2(double x)
Calculate the logarithm using base 2.float
fastLog2(float x)
Calculate the logarithm using base 2.double
getBase()
Gets the base.int
getN()
Gets the number of most significant bits to keep from the mantissa, i.e.double
getScale()
Gets the scale to convert from log2 to logB (the base given byFastLog.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
-
FFastLog
public FFastLog()
Create a new natural logarithm calculation instance.
-
FFastLog
public FFastLog(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
-
FFastLog
public FFastLog(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.
-
getScale
public double getScale()
Description copied from class:FastLog
Gets the scale to convert from log2 to logB (the base given byFastLog.getBase()
) by multiplication.
-
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.
-
log2
public float log2(float 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.
-
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.
-
fastLog2
public float fastLog2(float x)
Calculate the logarithm using base 2. Requires the argument be finite and positive.Special cases:
- If the argument is NaN, then the result is incorrect
(
>fastLog2(Float.MAX_VALUE)
). - If the argument is negative, then the result is incorrect
(
fastLog2(-x)
). - If the argument is positive infinity, then the result is incorrect
(
fastLog2(Float.MAX_VALUE)
). - If the argument is positive zero or negative zero, then the result is negative infinity.
- If the argument is NaN, then the result is incorrect
(
-
fastLog2
public float fastLog2(double x)
Calculate the logarithm using base 2. Requires the argument be finite and positive.Special cases:
- If the argument is NaN, then the result is incorrect
(
>fastLog2(Float.MAX_VALUE)
). - If the argument is negative, then the result is incorrect
(
fastLog2(-x)
). - If the argument is positive infinity, then the result is incorrect
(
fastLog2(Float.MAX_VALUE)
). - If the argument is positive zero or negative zero, then the result is negative infinity.
- If the argument is NaN, then the result is incorrect
(
-
log
public float log(float 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 classFastLog
- Parameters:
x
- the argument- Returns:
- log(x)
- See Also:
FastLog.getBase()
-
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 classFastLog
- Parameters:
x
- the argument- Returns:
- log(x)
- See Also:
FastLog.getBase()
-
fastLog
public float fastLog(float 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
(
>fastLog(Float.MAX_VALUE)
). - If the argument is negative, then the result is incorrect
(
fastLog(-x)
). - If the argument is positive infinity, then the result is incorrect
(
fastLog(Float.MAX_VALUE)
). - If the argument is positive zero or negative zero, then the result is negative infinity.
- Specified by:
fastLog
in classFastLog
- Parameters:
x
- the argument (must be strictly positive)- Returns:
- log( x )
- See Also:
FastLog.getBase()
- If the argument is NaN, then the result is incorrect
(
-
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
(
>fastLog(Float.MAX_VALUE)
). - If the argument is negative, then the result is incorrect
(
fastLog(-x)
). - If the argument is positive infinity, then the result is incorrect
(
fastLog(Float.MAX_VALUE)
). - If the argument is positive zero or negative zero, then the result is negative infinity.
- Specified by:
fastLog
in classFastLog
- Parameters:
x
- the argument (must be strictly positive)- Returns:
- log( x )
- See Also:
FastLog.getBase()
- If the argument is NaN, then the result is incorrect
(
-
-