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?

[306 byte] By [Marcus@Romseya] at [2007-10-3 3:31:48]
# 1

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();

}

}

leoncinaa at 2007-7-14 21:25:52 > top of Java-index,Java Essentials,Java Programming...
# 2
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.
Marcus@Romseya at 2007-7-14 21:25:52 > top of Java-index,Java Essentials,Java Programming...
# 3
The answer to why NaN isn't supported is because BigDecimal in its present form can't generate them.
ejpa at 2007-7-14 21:25:52 > top of Java-index,Java Essentials,Java Programming...