public class LogNumber extends java.lang.Number implements Field<LogNumber>, java.lang.Comparable<LogNumber>
UnsignedLogNumber instead,
since it does not have to maintain the sign information, so it will consume
less memory and will be faster.UnsignedLogNumber,
LogMath,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected double |
logValue
The log of the absolute value represented by this object, log(|value|).
|
protected boolean |
negative
The sign of the value, sign(value).
|
| Modifier | Constructor and Description |
|---|---|
|
LogNumber()
Creates the
LogNumber representing zero. |
protected |
LogNumber(boolean negative,
double logValue)
Creates a new
LogNumber from the given value in log-space. |
|
LogNumber(LogNumber other)
Copies a given LogNumber.
|
| Modifier and Type | Method and Description |
|---|---|
LogNumber |
absoluteValue()
Returns a new
LogNumber that represents the absolute value
of this LogNumber. |
void |
absoluteValueEquals()
Transforms this value to be its absolute value.
|
LogNumber |
clone()
Returns a smart copy of
this, such that changing the values
of the return class will not effect this |
int |
compareTo(LogNumber other) |
static LogNumber |
createFromLogValue(boolean negative,
double logValue)
Creates a new
LogNumber from the given value that is
already in log-space. |
static LogNumber |
createFromLogValue(double logValue)
Creates a new
LogNumber from the given value that is
already in log-space. |
static LogNumber |
createFromValue(double value)
Creates a new
LogNumber from the given value. |
LogNumber |
divide(LogNumber other)
Divides this value by another value and returns the result.
|
void |
divideEquals(LogNumber other)
Divides this value by another value and stores the result in
this value.
|
LogNumber |
dotTimes(LogNumber other)
Element-wise multiplication of
this and other |
void |
dotTimesEquals(LogNumber other)
Inline element-wise multiplication of
this and
other |
double |
doubleValue() |
boolean |
equals(LogNumber other,
double effectiveZero)
Determines if two RingType objects are effectively equal
|
boolean |
equals(java.lang.Object other)
Determines if two RingType objects are equal
|
float |
floatValue() |
double |
getLogValue()
Gets the log of the value represented by this object, which is what is
stored in the object.
|
double |
getValue()
Gets the value represented by the log number.
|
int |
hashCode() |
int |
intValue() |
LogNumber |
inverse()
Returns the inverse of
this. |
void |
inverseEquals()
Changes this value to be its inverse.
|
boolean |
isNegative()
Gets whether or not this value has a negative sign.
|
boolean |
isZero()
Determines if this ring is equal to zero.
|
boolean |
isZero(double effectiveZero)
Determines if this ring is equal to zero using the element-wise effective
zero value.
|
long |
longValue() |
LogNumber |
max(LogNumber other)
A new
LogNumber that is the maximum of this and another. |
void |
maxEquals(LogNumber other)
Changes this value to be the maximum of this value or the given value.
|
LogNumber |
min(LogNumber other)
A new
LogNumber that is the minimum of this and another. |
void |
minEquals(LogNumber other)
Changes this value to be the minimum of this value or the given value.
|
LogNumber |
minus(LogNumber other)
Arithmetic subtraction of
other from this |
void |
minusEquals(LogNumber other)
Inline arithmetic subtraction of
other from
this |
LogNumber |
negative()
Returns the element-wise negation of
this, such that
this.plus( this.negative() ) has only zero elements. |
void |
negativeEquals()
Inline element-wise negation of
this |
LogNumber |
plus(LogNumber other)
Arithmetic addition of
this and other |
void |
plusEquals(LogNumber other)
Inline arithmetic addition of
this and other |
LogNumber |
power(double power)
Returns a new
LogNumber representing this log number taken
to the given power. |
void |
powerEquals(double power)
Transforms this log number by taking it to the given power.
|
LogNumber |
scale(double scaleFactor)
Element-wise scaling of
this by scaleFactor |
LogNumber |
scaledMinus(double scaleFactor,
LogNumber other)
Arithmetic subtraction
other after element-wise scaling of
other by scaleFactor from this. |
void |
scaledMinusEquals(double scaleFactor,
LogNumber other)
Inline arithmetic subtraction of
other after element-wise
scaling of other by scaleFactor from this. |
LogNumber |
scaledPlus(double scaleFactor,
LogNumber other)
Arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor. |
void |
scaledPlusEquals(double scaleFactor,
LogNumber other)
Inline arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor. |
void |
scaleEquals(double scaleFactor)
Inline element-wise scaling of
this by
scaleFactor |
void |
setLogValue(double logValue)
Sets the log of the value represented by this object, which is what is
stored in the object.
|
void |
setNegative(boolean negative)
Sets whether or not this value has a negative sign.
|
void |
setValue(double value)
Sets the value represented by the log number.
|
LogNumber |
times(LogNumber other)
Multiples this value times another value and returns the result.
|
void |
timesEquals(LogNumber other)
Multiplies this value times another value and stores the result in
this value.
|
java.lang.String |
toString() |
void |
zero()
Zeros out all elements of
this, so that the following are
equivalent
r1.scaleEquals( 0.0 );
and
r1.zero();
Furthermore,
r1.zero(); anything.dotTimes( r1 ).equals( r1 ); |
protected boolean negative
protected double logValue
public LogNumber()
LogNumber representing zero.protected LogNumber(boolean negative,
double logValue)
LogNumber from the given value in log-space.
This method is protected to avoid people calling it with being unsure if
value or log(value) should be given. Thus, two separate static utility
functions createFromValue and createFromLogValue are to be used instead.negative - The flag indicating if the value is positive (false) or negative
(true).logValue - The log(value) for the value to be represented by this
LogNumber.public LogNumber(LogNumber other)
other - The LogNumber to copy.public static LogNumber createFromValue(double value)
LogNumber from the given value.value - A normal value.public static LogNumber createFromLogValue(double logValue)
LogNumber from the given value that is
already in log-space. Equivalent to calling createFromValue(
exp(logValue)) or createFromLogValue(false, logValue).logValue - The value that is already in log-space.public static LogNumber createFromLogValue(boolean negative, double logValue)
LogNumber from the given value that is
already in log-space. Equivalent to calling createFromValue(
(negative ? +1.0 : -1.0) * exp(logValue)).negative - True if the value is negative.logValue - The value that is already in log-space.public LogNumber clone()
Ringthis, such that changing the values
of the return class will not effect thisclone in interface Ring<LogNumber>clone in interface CloneableSerializableclone in class java.lang.Objectthispublic boolean equals(java.lang.Object other)
Ringpublic boolean equals(LogNumber other, double effectiveZero)
Ringpublic int compareTo(LogNumber other)
compareTo in interface java.lang.Comparable<LogNumber>public int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic LogNumber plus(LogNumber other)
Ringthis and otherpublic void plusEquals(LogNumber other)
Ringthis and otherplusEquals in interface Ring<LogNumber>other - object to add to thispublic LogNumber minus(LogNumber other)
Ringother from thispublic void minusEquals(LogNumber other)
Ringother from
thisminusEquals in interface Ring<LogNumber>other - object to subtract from thispublic LogNumber times(LogNumber other)
times in interface EuclideanRing<LogNumber>other - The other value.public void timesEquals(LogNumber other)
timesEquals in interface EuclideanRing<LogNumber>other - The other value.public LogNumber divide(LogNumber other)
divide in interface EuclideanRing<LogNumber>other - The other value.public void divideEquals(LogNumber other)
divideEquals in interface EuclideanRing<LogNumber>other - The other value.public LogNumber dotTimes(LogNumber other)
Ringthis and otherpublic void dotTimesEquals(LogNumber other)
Ringthis and
otherdotTimesEquals in interface Ring<LogNumber>other - elements of other will be multiplied to the corresponding
elements of thispublic LogNumber scale(double scaleFactor)
Ringthis by scaleFactorpublic void scaleEquals(double scaleFactor)
Ringthis by
scaleFactorscaleEquals in interface Ring<LogNumber>scaleFactor - amount to scale the elements of thispublic LogNumber scaledPlus(double scaleFactor, LogNumber other)
Ringthis and other after
element-wise scaling of other by scaleFactor.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x + a * y. It is typically a more efficient way of doing
this.plus(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledPlus in interface Ring<LogNumber>scaleFactor - The scale factor to multiply by the elements of other before
adding to the elements of this.other - Object to scale and then add to this.public void scaledPlusEquals(double scaleFactor,
LogNumber other)
Ringthis and other after
element-wise scaling of other by scaleFactor.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x += a * y. It is typically a more efficient way of doing
this.plusEquals(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledPlusEquals in interface Ring<LogNumber>scaleFactor - The scale factor to multiply by the elements of other before
adding to the elements of this.other - Object to scale and then add to this.public LogNumber scaledMinus(double scaleFactor, LogNumber other)
Ringother after element-wise scaling of
other by scaleFactor from this.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x - a * y. It is typically a more efficient way of doing
this.minus(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledMinus in interface Ring<LogNumber>scaleFactor - The scale factor to multiply by the elements of other before
subtracting from the elements of this.other - Object to scale and then subtract from this.public void scaledMinusEquals(double scaleFactor,
LogNumber other)
Ringother after element-wise
scaling of other by scaleFactor from this.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x -= a * y. It is typically a more efficient way of doing
this.minusEquals(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledMinusEquals in interface Ring<LogNumber>scaleFactor - The scale factor to multiply by the elements of other before
adding to the elements of this.other - Object to scale and then add to this.public LogNumber negative()
Ringthis, such that
this.plus( this.negative() ) has only zero elements.public void negativeEquals()
RingthisnegativeEquals in interface Ring<LogNumber>public void inverseEquals()
FieldinverseEquals in interface Field<LogNumber>public LogNumber inverse()
Fieldthis.public void zero()
Ringthis, so that the following are
equivalent
r1.scaleEquals( 0.0 );
and
r1.zero();
Furthermore,
r1.zero(); anything.dotTimes( r1 ).equals( r1 );public boolean isZero()
Ringpublic boolean isZero(double effectiveZero)
Ringpublic LogNumber absoluteValue()
LogNumber that represents the absolute value
of this LogNumber.public void absoluteValueEquals()
public LogNumber power(double power)
LogNumber representing this log number taken
to the given power.power - The power.public void powerEquals(double power)
power - The power.public LogNumber min(LogNumber other)
LogNumber that is the minimum of this and another.other - Another value.public void minEquals(LogNumber other)
other - Another value.public LogNumber max(LogNumber other)
LogNumber that is the maximum of this and another.other - Another value.public void maxEquals(LogNumber other)
other - Another value.public double getValue()
public void setValue(double value)
value - The value for this object to represent.public boolean isNegative()
public void setNegative(boolean negative)
negative - True if this value has a negative sign.public double getLogValue()
public void setLogValue(double logValue)
logValue - The log of the value for this object to represent.public int intValue()
intValue in class java.lang.Numberpublic long longValue()
longValue in class java.lang.Numberpublic float floatValue()
floatValue in class java.lang.Numberpublic double doubleValue()
doubleValue in class java.lang.Number