jjil.core
Class MathPlus

java.lang.Object
  extended by jjil.core.MathPlus

public class MathPlus
extends java.lang.Object

Mathematical routines which are normally provided by the Java Math class but which aren't available with CLDC 1.0.

Author:
webb

Field Summary
static int PI
          PI, scaled by SCALE.
static int SCALE
          The scale factor for this class.
static int SHIFT
          Number of log base 2 of SCALE.
 
Constructor Summary
MathPlus()
           
 
Method Summary
static int cos(int x)
          Returns the cosine of the argument, scaled by SCALE.
static Complex expImag(int x)
          Returns the complex number e**(ix), that is,
cos x + i sin x (de Moivre's rule)
static int sign(int x)
          Returns sign of the argument: 0 if arg = 0, 1 if arg is > 0, -1 otherwise.
static int sin(int x)
          Returns the sine of the argument, scaled by SCALE.
static int sqrt(int x)
          Computes square root using Newton's iteration.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PI

public static int PI
PI, scaled by SCALE.


SCALE

public static int SCALE
The scale factor for this class. parameters and results are scaled by this factor, currently 2**16 = 65536.


SHIFT

public static int SHIFT
Number of log base 2 of SCALE. Used when we want to divide or multiply using shifting.

Constructor Detail

MathPlus

public MathPlus()
Method Detail

cos

public static int cos(int x)
Returns the cosine of the argument, scaled by SCALE. The argument also must be scaled by SCALE. The calculation is done using the Taylor series expansion.

Parameters:
x - the angle to take the sin of (measured in radians).
Returns:
the sin of the provided angle.

expImag

public static Complex expImag(int x)
Returns the complex number e**(ix), that is,
cos x + i sin x (de Moivre's rule)

Parameters:
x - the number to compute the imaginary exponential of. Should be scaled by SCALE, as is the result.
Returns:
e**(ix), i.e., cos x + i sin x, scaled by SCALE.

sign

public static int sign(int x)
Returns sign of the argument: 0 if arg = 0, 1 if arg is > 0, -1 otherwise.

Parameters:
x - Number to take the sign of.
Returns:
the sign of the argument:
0 if arg = 0
1 if arg > 0
-1 if arg < 0.

sin

public static int sin(int x)
Returns the sine of the argument, scaled by SCALE. The argument also must be scaled by SCALE. The calculation is done using the Taylor series expansion.

Parameters:
x - the angle to take the sin of (measured in radians).
Returns:
the sin of the provided angle.

sqrt

public static int sqrt(int x)
                throws Error
Computes square root using Newton's iteration.

Parameters:
x - number to take square root of
Returns:
the square root of x
Throws:
Error - if x < 0