jcontrol.lang
Class Math

java.lang.Object
  extended by jcontrol.lang.Math

public class Math
extends Object

Provides some simple math functions.

JControl devices are limited in computation rate and precision, so some useful mathematical functions are approximated with tables.

Version:
1.0
Author:
Andreas Wesseler, Helge Böhme
Available on JControl Devices:
all

Method Summary
static int cos(int op)
          Look-up table cosine function.
static int rnd(int mod)
          Returns a pseudo random number.
static int scale(int value, int source, int dest)
          Rule of proportion.
static int sin(int op)
          Look-up table sine function.
static int sqrt(int op)
          Look-up table square root.
 
Methods inherited from class java.lang.Object
clone, equals, notifyAll, wait
 

Method Detail

cos

public static int cos(int op)
Look-up table cosine function. The result is scaled to full integer range.

Parameters:
op - function argument in degrees (range 0 ... 360)
Returns:
scaled cosine (-32767 ... 32767)

rnd

public static int rnd(int mod)
Returns a pseudo random number.

Parameters:
mod - the range for the random number (1...mod-1), 0 for full 15 bit range
Returns:
the random number

scale

public static int scale(int value,
                        int source,
                        int dest)
Rule of proportion. As some JControl implementations are only able to calculate in 16 bit domain, this function could help scaling e.g. coordinates or control variables. The intermediate result of the multiplication will have 32 bit, the division takes these 32 bit and returns 16 bit. y=scale(x,a,b) is equal to y=x*b/a.

Parameters:
value - the value to scale (range -32768 ... 32767)
source - the divisor (range -32768 ... 32767)
dest - the multiplicant (range -32768 ... 32767)
Returns:
scaled value (range -32768 ... 32767)

sin

public static int sin(int op)
Look-up table sine function. The result is scaled to full integer range.

Parameters:
op - function argument in degrees (range 0 ... 360)
Returns:
scaled sine (-32767 ... 32767)

sqrt

public static int sqrt(int op)
Look-up table square root.

Parameters:
op - value to extract the root from (range: 0 ... 32767)
Returns:
floor of square root (range 0 ... 181)