Re: Double precision issue

You need to understand that digital computers cannot represent floating point numbers to exact precision. This has nothing to do with Java and all to do with a basic engineering fact. If you need greater precision than is afforded by double values, consider using BigDecimal numbers, but realize that by doing so your program will take a memory and performance hit.

You can find out more on double's precision from the JLS here: 4.2.3. Floating-Point Types, Formats, and Values

and from the IEEE specification which Java follows: IEEE 754-1985

Re: Double precision issue

A double value can store +- 15 significant digits (53 bits) an a 10 bit binary exponent. Your numbers are considered equal within an accuracy of 15 digits.

kind regards,

Jos

Re: Double precision issue

Hmm, thanks,

I do realize the issue of representing real values with binary precision, still, 1+10e-16 and 1+10e-17 are subjectively very different. There is no way to realize that difference with double precision type? That is a 64 bit precision, which I think should be able to cover much smaller differences. I'll look into BigDecimal I suppose.

EDIT: just saw the response above. Thanks! I take it there is no datatype that handles bigger precision then 15 sd's , other then BigDecimal?

Re: Double precision issue

The numbers are 1+1e-16 and 1+1e-17; they don't differ in 15 significant decimals: 1 is 1e16 times as big as the first number and 1e17 times as big as the second number. A double does take up 64 bits but 10 bits are for the (binary, biased) exponent and 1 bit is the sign bit ...

kind regards,

Jos

Re: Double precision issue

Nope

That's one of the things BigDecimal is for.

The other being that it's accurate, which is why it's used for money things.