de.dante.extex.interpreter.type.scaled
Class ScaledNumber

java.lang.Object
  extended byde.dante.extex.interpreter.type.scaled.ScaledNumber

public class ScaledNumber
extends java.lang.Object

This class provides a fixed point number.

Version:
$Revision: 1.8 $
Author:
Gerd Neugebauer

Field Summary
static long ONE
          The constant ONE contains the internal representation for 1pt.
 
Constructor Summary
ScaledNumber()
          Creates a new object.
 
Method Summary
 void add(long scaled)
          Add a number to the current one.
 void add(ScaledNumber scaled)
          Add a number to the current one.
 void divide(long scaled)
          Divide the scaled value by a number.
 boolean eq(ScaledNumber d)
          Compares the current instance with another ScaledNumber for equality.
 boolean ge(ScaledNumber d)
          Compares the current instance with another ScaledNumber.
 long getValue()
          Getter for the value.
 boolean le(ScaledNumber d)
          Compares the current instance with another ScaledNumber.
 boolean lt(ScaledNumber d)
          Compares the current instance with another ScaledNumber.
 void multiply(long scaled)
          Multiply the current value by a scaled number.
 void multiply(long nom, long denom)
          Multiply the value by an integer fraction.
 void negate()
          Negate the current value.
static long parse(Context context, TokenSource source, Typesetter typesetter)
          Evaluate an expression.
static long scanFloat(Context context, TokenSource source, Typesetter typesetter, Token start)
          Parses a token stream for a float and returns it as fixed point number.
static ScaledNumber scanScaledNumber(Context context, TokenSource source, Typesetter typesetter)
          Parses a token stream for a float and returns it as fixed point number.
 void set(long scaled)
          Set the value to a new one
 void set(ScaledNumber scaled)
          Setter for the value
 void subtract(ScaledNumber scaled)
          Subtract a number from the current one.
 java.lang.String toString()
          Determine the printable representation of the object.
static void toString(java.lang.StringBuffer sb, long value)
          Determine the printable representation of the object and append it to the given StringBuffer.
 void toToks(Tokens toks, TokenFactory factory)
          Determine the printable representation of the object and return it as a list of Tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE

public static final long ONE
The constant ONE contains the internal representation for 1pt.

See Also:
"TeX – The Program [101]", Constant Field Values
Constructor Detail

ScaledNumber

public ScaledNumber()
Creates a new object.

Method Detail

parse

public static long parse(Context context,
                         TokenSource source,
                         Typesetter typesetter)
                  throws InterpreterException
Evaluate an expression.

Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
Returns:
the result
Throws:
InterpreterException - in case of an error

scanFloat

public static long scanFloat(Context context,
                             TokenSource source,
                             Typesetter typesetter,
                             Token start)
                      throws InterpreterException
Parses a token stream for a float and returns it as fixed point number.

Parameters:
context - the interpreter context
source - the source for new tokens
start - the initial token to start with
Returns:
the fixed point representation of the floating number in units of 2-16.
Throws:
InterpreterException - in case of an error

scanScaledNumber

public static ScaledNumber scanScaledNumber(Context context,
                                            TokenSource source,
                                            Typesetter typesetter)
                                     throws InterpreterException
Parses a token stream for a float and returns it as fixed point number.

Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
Returns:
the fixed point representation of the floating point number
Throws:
InterpreterException - in case of an error

toString

public static void toString(java.lang.StringBuffer sb,
                            long value)
Determine the printable representation of the object and append it to the given StringBuffer.

Parameters:
sb - the output string buffer
value - the internal value in multiples of ONE

add

public void add(long scaled)
Add a number to the current one.

Parameters:
scaled - the number to add

add

public void add(ScaledNumber scaled)
Add a number to the current one.

Parameters:
scaled - the number to add

divide

public void divide(long scaled)
Divide the scaled value by a number.

Parameters:
scaled - the divisor

eq

public boolean eq(ScaledNumber d)
Compares the current instance with another ScaledNumber for equality.

Parameters:
d - the other ScaledNumber to compare to. If this parameter is null then the comparison fails.
Returns:
true iff |this| == |d|

ge

public boolean ge(ScaledNumber d)
Compares the current instance with another ScaledNumber.

Parameters:
d - the other ScaledNumber to compare to
Returns:
true iff this is greater or equal to d

getValue

public long getValue()
Getter for the value.

Returns:
the value

le

public boolean le(ScaledNumber d)
Compares the current instance with another ScaledNumber.

Parameters:
d - the other ScaledNumber to compare to
Returns:
true iff this is less or equal to d

lt

public boolean lt(ScaledNumber d)
Compares the current instance with another ScaledNumber.

Parameters:
d - the other ScaledNumber to compare to
Returns:
true iff |this| < |d|

multiply

public void multiply(long scaled)
Multiply the current value by a scaled number.

Parameters:
scaled - the multiplicant

multiply

public void multiply(long nom,
                     long denom)
Multiply the value by an integer fraction.

length = length * nom / denom

Parameters:
nom - nominator
denom - denominator

negate

public void negate()
Negate the current value.


set

public void set(long scaled)
Set the value to a new one

Parameters:
scaled - the new value

set

public void set(ScaledNumber scaled)
Setter for the value

Parameters:
scaled - the new value

subtract

public void subtract(ScaledNumber scaled)
Subtract a number from the current one.

Parameters:
scaled - the number to subtract

toString

public java.lang.String toString()
Determine the printable representation of the object.

Returns:
the printable representation
See Also:
#toString(StringBuffer), toToks(Tokens,TokenFactory)

toToks

public void toToks(Tokens toks,
                   TokenFactory factory)
            throws CatcodeException
Determine the printable representation of the object and return it as a list of Tokens. The value returned is exactly the string which would be produced by TeX to print the Dimen. This means the result is expressed in pt and properly rounded to be read back in again without loss of information.

Parameters:
toks - the tokens to append to
factory - the token factory to get the required tokens from
Throws:
CatcodeException - in case of an error
See Also:
"TeX – The Program [103]"