Thursday 4 June 2020

The Dangers of Doubles

The problems with Doubles and Floats are already well documented, but sometimes we fall into the trap again.

In short, the representation of a real number1 in Float and Double is not precise2.

Normally, I am well aware of this limitation, but sometimes I get tripped up by already receiving Doubles and Floats as input.

In this case, it involved Geometrie coordinates, in doubles of course.

The following Unit Test shows the problem:

References

[1] Wikipedia - Real number
https://en.wikipedia.org/wiki/Real_number
[2] What Every Programmer Should Know About Floating-Point Arithmetic
https://floating-point-gui.de/

No comments:

Post a Comment