edu.stanford.nlp.math
Class ScientificNotationDouble

java.lang.Object
  |
  +--java.lang.Number
        |
        +--edu.stanford.nlp.math.ScientificNotationDouble
All Implemented Interfaces:
Serializable

public class ScientificNotationDouble
extends Number

ScientificNotationDouble allows very small and very large numbers to be multiplied without causing a floating point underflow/overflow. has a base (which is a double x s.t. 1<=x<10), and an exponent such that the double value of ScientificNotationDouble is base * 10^exponent note: ScientificNotationDouble does not handle negative numbers. this is to increase the speed.

See Also:
Serialized Form

Constructor Summary
ScientificNotationDouble()
          creates a new ScientificNotationDouble with value 0
ScientificNotationDouble(double d)
          constructs ScientificNotationDouble from a standard double
ScientificNotationDouble(double b, int e)
          constructs ScientificNotationDouble given a base b and an exponent e
ScientificNotationDouble(int i)
          constructs ScientificNotationDouble from a standard int
ScientificNotationDouble(ScientificNotationDouble other)
          constructs ScientificNotationDouble from another ScientificNotationDouble
 
Method Summary
 ScientificNotationDouble add(ScientificNotationDouble addend)
          returns the sum of this and addend
 ScientificNotationDouble divide(ScientificNotationDouble divisor)
           
 double doubleValue()
           
 void ensureProperBase()
          ensures that the base of the ScientificNotationDouble is >=1 and <10.
 float floatValue()
           
 double getBase()
           
 int getExponent()
           
 int intValue()
           
 long longValue()
           
 ScientificNotationDouble multiply(ScientificNotationDouble multiplicand)
          returns product of this with multiplicand
 void reset()
          sets to zero
 ScientificNotationDouble scale(int e)
          returns a ScientificNotationdouble whose base is scaled so that it = base * 10^e the base may no longer be >=1 and <10 does not change this
 void set(double d)
           
 void set(double b, int e)
           
 void set(int i)
           
 void setBase(double b)
           
 void setExponent(int e)
           
 void setSmallToZero(int tolerance)
          set numbers which are smaller than 10^tolerance = 0 the tolerance should usually be a large negative number
 String toString()
           
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScientificNotationDouble

public ScientificNotationDouble()
creates a new ScientificNotationDouble with value 0


ScientificNotationDouble

public ScientificNotationDouble(int i)
constructs ScientificNotationDouble from a standard int


ScientificNotationDouble

public ScientificNotationDouble(double d)
constructs ScientificNotationDouble from a standard double


ScientificNotationDouble

public ScientificNotationDouble(double b,
                                int e)
constructs ScientificNotationDouble given a base b and an exponent e


ScientificNotationDouble

public ScientificNotationDouble(ScientificNotationDouble other)
constructs ScientificNotationDouble from another ScientificNotationDouble

Method Detail

getBase

public double getBase()

getExponent

public int getExponent()

setBase

public void setBase(double b)

setExponent

public void setExponent(int e)

set

public void set(double b,
                int e)

reset

public void reset()
sets to zero


set

public void set(double d)

set

public void set(int i)

scale

public ScientificNotationDouble scale(int e)
returns a ScientificNotationdouble whose base is scaled so that it = base * 10^e the base may no longer be >=1 and <10 does not change this


ensureProperBase

public void ensureProperBase()
ensures that the base of the ScientificNotationDouble is >=1 and <10. used within addition, multiplication, and division routines


multiply

public ScientificNotationDouble multiply(ScientificNotationDouble multiplicand)
returns product of this with multiplicand


divide

public ScientificNotationDouble divide(ScientificNotationDouble divisor)

add

public ScientificNotationDouble add(ScientificNotationDouble addend)
returns the sum of this and addend


doubleValue

public double doubleValue()
Specified by:
doubleValue in class Number

floatValue

public float floatValue()
Specified by:
floatValue in class Number

intValue

public int intValue()
Specified by:
intValue in class Number

longValue

public long longValue()
Specified by:
longValue in class Number

toString

public String toString()
Overrides:
toString in class Object

setSmallToZero

public void setSmallToZero(int tolerance)
set numbers which are smaller than 10^tolerance = 0 the tolerance should usually be a large negative number



Stanford NLP Group