generator.engin.utils
Class AdjustPrecision

java.lang.Object
  extended by generator.engin.utils.AdjustPrecision

public class AdjustPrecision
extends java.lang.Object

AdjustPrecision

This class is used to round real numbers at the specified maximum number of decimals. A number can be eighter rounded up or down depending of the situation. All methods are static, hence the class cannot be instanced.

Copyright(c) 2005 Université Laval, LSFM research group.

Version:
1.1
Author:
Frédérick Lemay

Constructor Summary
AdjustPrecision()
           
 
Method Summary
static int getPrecision()
          Returns the current maximum number of decimals
static void mustContain(int maxDecimalPart)
          Automatically increase the current maximum number of decimals if the specified maximum decimal part value cannot be represented using the current maximum number of decimals.
static double roundUp(double number)
          This method round a real number to the nearest superior decimal at the specified maximum number of decimals.
static void setPrecision(int precision)
          Sets the maximum number of decimals allowed in a real number.
static double truncate(double number)
          This method truncates a real number at the specified maximum number of decimals.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AdjustPrecision

public AdjustPrecision()
Method Detail

truncate

public static double truncate(double number)
This method truncates a real number at the specified maximum number of decimals. Zeroes will not be added to pad the number to the number of decimals.

Parameters:
number - the number to truncate
Returns:
the truncated number

roundUp

public static double roundUp(double number)
This method round a real number to the nearest superior decimal at the specified maximum number of decimals. Zeroes will not be added to pad the number to the number of decimals.

Parameters:
number - the number to round
Returns:
the rounded number

setPrecision

public static void setPrecision(int precision)
                         throws ParameterException
Sets the maximum number of decimals allowed in a real number. This method will be ineffective if the number is not included between 1 and 16.

Parameters:
precision - the number of decimals to keep
Throws:
ParameterException - should the precision specified be invalid

getPrecision

public static int getPrecision()
Returns the current maximum number of decimals

Returns:
the current maximum number of decimals

mustContain

public static void mustContain(int maxDecimalPart)
Automatically increase the current maximum number of decimals if the specified maximum decimal part value cannot be represented using the current maximum number of decimals.

Parameters:
maxDecimalPart - the largest decimal part to be represented