texsoft.java.util
Class XsMath

java.lang.Object
  |
  +--texsoft.java.util.XsMath

public abstract class XsMath
extends java.lang.Object

This abstract class provides some math static methods, moslty for rounding purposes.


Constructor Summary
XsMath()
           
 
Method Summary
static double log10(double x)
          Returns the log10 of x.
static void main(java.lang.String[] args)
          Simple test code.
static double pow10(int pow)
          Return 10pow.
static double round(double value, int log)
          Round value to log decimal weight.
static double roundDown(double value, int log)
          Round DOWN value to log decimal weight.
static double roundUp(double value, int log)
          Round UP value to log decimal weight.
static double trunc(double value, int log)
          Truncate value to log decimal weight.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XsMath

public XsMath()
Method Detail

trunc

public static double trunc(double value,
                           int log)
Truncate value to log decimal weight.

Use negative log value for decimal. Examples:

 trunc(123.456, -4) = 123.456
 trunc(123.456, -3) = 123.456
 trunc(123.456, -2) = 123.45
 trunc(123.456, -1) = 123.4
 trunc(123.456,  0) = 123.0
 trunc(123.456,  1) = 120.0
 trunc(123.456,  2) = 100.0
 trunc(123.456,  3) = 0.0
 

Parameters:
value - value to be truncated.
log - truncate value to the this decimal weight. Negative values mean decimal positions.
Returns:
value truncated to the given decimal weight.

round

public static double round(double value,
                           int log)
Round value to log decimal weight.

Use negative log value for decimals. Examples:

 round(123.446, -4)=123.446
 round(123.446, -3)=123.446
 round(123.446, -2)=123.45
 round(123.446, -1)=123.4
 round(123.446, 0)=123.0
 round(123.446, 1)=120.0
 round(153.446, 2)=200.0
 round(123.446, 3)=0.0
 

Parameters:
value - value to be rounded.
log - round value to the this decimal weight. Negative values mean decimal positions.
Returns:
value rounded to the given decimal weight.

roundUp

public static double roundUp(double value,
                             int log)
Round UP value to log decimal weight.

Use negative log value for decimals. Examples:

 roundUp(123.456, -4) = 123.456
 roundUp(123.456, -3) = 123.456
 roundUp(123.456, -2) = 123.46
 roundUp(123.456, -1) = 123.5
 roundUp(123.456, 0)  = 124.0
 roundUp(123.456, 1)  = 130.0
 roundUp(123.456, 2)  = 200.0
 roundUp(123.456, 3)  = 1000.0
 

Parameters:
value - value to be rounded up.
log - round up value to the this decimal weight. Negative values mean decimal positions.
Returns:
value rounded up to the given decimal weight.

roundDown

public static double roundDown(double value,
                               int log)
Round DOWN value to log decimal weight.

Use negative log value for decimals. Examples:

 roundDown(123.456, -4)=123.456
 roundDown(123.456, -3)=123.456
 roundDown(123.456, -2)=123.45
 roundDown(123.456, -1)=123.4
 roundDown(123.456, 0)=123.0
 roundDown(123.456, 1)=120.0
 roundDown(123.456, 2)=100.0
 roundDown(123.456, 3)=0.0
 

Parameters:
value - value to be rounded down.
log - round down value to the this decimal weight. Negative values mean decimal positions.
Returns:
value rounded down to the given decimal weight.

pow10

public static double pow10(int pow)
Return 10pow.

Parameters:
pow - exponent.
Returns:
10pow.

log10

public static double log10(double x)
Returns the log10 of x.

Parameters:
x - value whose log10 has to be calculated.
Returns:
log10 of x.

main

public static void main(java.lang.String[] args)
Simple test code.

Parameters:
args - command line arguments.