BigDecimal Elementary Functions
Are there any plans to add elementary functions to the BigDecimal class? Other than using the functions in the Apfloat package, does anyone know of a BigDecimal elementary function library/package?
Why do BigDecimals not support NaN and the other useful flags supported by IEEE floating point?
Hi,
you can see documentation at:
http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html
to add function you can create a new class that extends BigDecimal.
For example:
import java.math.BigDecimal;
public class MyBigDecimal extends BigDecimal {
private int val = 0;
/**
* my constructor
* @param val
*/
public MyBigDecimal(int val) {
super(val);
this.val = val;
}
/**
* overwrite a BigDecimal method
*/
public BigDecimal divide(BigDecimal divisor, int scale, int roundingMode) {
return null;
}
/**
* my method
* @return
*/
public void printMyMethod() {
System.out.println("val is: " + this.val);
}
public static void main(String[] args) {
MyBigDecimal myBigDecimal = new MyBigDecimal(10);
myBigDecimal.printMyMethod();
}
}
Thank you for your reply, however, I think you must have misunderstood the question. By elementary functions, I am referring to sqrt, sin, sinh,asin, log, ln, exp etc. For floats and doubles these are java.lang.Math.