Is there any way to introduce Double.NaN in BigDecimal?
No. The class BigDecimaldoes not provide a representation for NaN, + ∞ or -∞.
You can use null... except that you need at least 3 different values nullto represent the three possible cases, and that is not possible.
BigDecimal, "" , "" BigDecimal NaN .. ; .
public class MyNumber {
private BigDecimal value;
private boolean isNaN;
...
private MyNumber(BigDecimal value, boolean isNaN) {
this.value = value;
this.isNaN = isNan;
}
public MyNumber multiply(MyNumber other) {
if (this.isNaN || other.isNaN) {
return new MyNumber(null, true);
} else {
return new MyNumber(this.value.multiply(other.value), false);
}
}
}