Check out this API:
http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html
I believe you can create arbitrarily small/precise decimals using an
implementation of this class.
mearvk
> I have a requirement to represent a very very small number in a java
> class of mine:
[quoted text clipped - 10 lines]
> Thanks in advance,
> A.
How about
double a = 2.2204e-16d;
where the final 'd' makes sure it is a double literal; otherwise it
would be a 'real', implicitly casted to a 'double'!
Life can be that easy....
HTH
Andreas
Mark Thornton - 07 Dec 2006 20:13 GMT
>> I have a requirement to represent a very very small number in a java
>> class of mine:
[quoted text clipped - 17 lines]
> where the final 'd' makes sure it is a double literal; otherwise it
> would be a 'real', implicitly casted to a 'double'!
You don't need the 'd' suffix --- floating point values are double by
default. So this suffices
double a = 2.2204e-16;
By contrast you do need the 'f' suffix here:
float a = 2.2204e-16f;
Mark Thornton
EJP - 07 Dec 2006 23:35 GMT
> double a = 2.2204e-16d;
>
> where the final 'd' makes sure it is a double literal; otherwise it
> would be a 'real', implicitly casted to a 'double'!
What's a 'real'? The 'e' is enough to mark it as a double, you don't
need the 'd' as well.
I should also add that since decimals are continuous (and the mapping
onto them is not), you only get a certain degree of accuracy using
Java's doubles. A double is 64 bits, which is quite alot. But remember,
there are an infinite number of decimals values between 0 and 1. So
when you do a comparison between two very small numbers which are
*similar*, the JVM may consider them to be equal, when in fact they are
not. This is where the BigDecimal implementation is a better solution.
May be germane, or not.
Mearvk