org.placelab.util
Class FixedPointLong

java.lang.Object
  extended byorg.placelab.util.FixedPointLong

public final class FixedPointLong
extends java.lang.Object

Implements fixed-point numbers in the long primitive type


Constructor Summary
FixedPointLong()
           
 
Method Summary
static long cos(long degreesFlong)
          returns the cosine of a flong, as a flong
static long div(long topFlong, long bottomFlong)
          returns a flong representing the division of the parameter flongs
static java.lang.String flongToString(long l)
          Makes a string from a flong, to the full precision available
static java.lang.String flongToString(long l, int dp)
          Makes a string from a flong, with precisely the specified number of decimal places
static long fracPart(long flong)
          returns a flong representing the fractional portion of the parameter flong
static long intPart(long flong)
          returns a flong representing the integer portion of the parameter flong
static long intToFlong(int i)
          make a flong from an integer
static long intToFlongSafe(int i)
          make a flong from an int, but without checking for overflow -- use this only on constants
static int intValue(long flong)
          returns the integer value, after rounding, of the flong
static long intValueRounded(long flong)
          rounded to the nearest integer
static long mult(long flongOne, long flongTwo)
          Returns a flong representing the multiple of the two parameter flongs
static long pythagoras(long x, long y)
          returns a flong representing sqrt(x*x+y*y), where x and y are the parameter flongs.
static long sqrt(long flong)
          returns the flong representing the positive square root of a flong
static long square(long flong)
          returns the flong representing the square of the parameter flong
static long stringToFlong(java.lang.String s)
          make a flong from a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedPointLong

public FixedPointLong()
Method Detail

intToFlongSafe

public static final long intToFlongSafe(int i)
make a flong from an int, but without checking for overflow -- use this only on constants


intToFlong

public static final long intToFlong(int i)
                             throws FixedPointLongException
make a flong from an integer

Throws:
FixedPointLongException - if an overflow occurs

stringToFlong

public static final long stringToFlong(java.lang.String s)
                                throws FixedPointLongException
make a flong from a string. E-notation numbers (e.g. -783.23E-6) are understood.

Throws:
FixedPointLongException - if the string is not parseable, or if overflow occurs

flongToString

public static final java.lang.String flongToString(long l)
                                            throws FixedPointLongException
Makes a string from a flong, to the full precision available

Throws:
FixedPointLongException

flongToString

public static final java.lang.String flongToString(long l,
                                                   int dp)
                                            throws FixedPointLongException
Makes a string from a flong, with precisely the specified number of decimal places

Throws:
FixedPointLongException

intPart

public static final long intPart(long flong)
returns a flong representing the integer portion of the parameter flong


fracPart

public static final long fracPart(long flong)
returns a flong representing the fractional portion of the parameter flong


intValue

public static final int intValue(long flong)
returns the integer value, after rounding, of the flong


cos

public static final long cos(long degreesFlong)
returns the cosine of a flong, as a flong


div

public static final long div(long topFlong,
                             long bottomFlong)
                      throws FixedPointLongException
returns a flong representing the division of the parameter flongs

Throws:
FixedPointLongException - if a divide-by-zero occurs

mult

public static long mult(long flongOne,
                        long flongTwo)
                 throws FixedPointLongException
Returns a flong representing the multiple of the two parameter flongs

Throws:
FixedPointLongException - if overflow occurs

square

public static long square(long flong)
                   throws FixedPointLongException
returns the flong representing the square of the parameter flong

Throws:
FixedPointLongException - if overflow occurs

sqrt

public static long sqrt(long flong)
                 throws FixedPointLongException
returns the flong representing the positive square root of a flong

Throws:
FixedPointLongException - if a negative number is passed in

pythagoras

public static long pythagoras(long x,
                              long y)
                       throws FixedPointLongException
returns a flong representing sqrt(x*x+y*y), where x and y are the parameter flongs. Use this rather than doing it yourself because this won't overflow with numbers who's square is above the representable limit.

Throws:
FixedPointLongException

intValueRounded

public static long intValueRounded(long flong)
rounded to the nearest integer