Search⌘ K
AI Features

Floating Point Types Usage and Limitations

Learn to choose between double, float, and real for floating point values in D programming. Understand the precision differences, representation issues with recurring decimals, and how special values like .nan affect comparisons. This lesson guides you through common pitfalls and best practices for handling floating point data types.

Which floating type to use

Unless there is a specific reason to choose otherwise, you can choose double for floating point values. float has lower precision than double and real, but it takes less number of bits and can be useful when we have limited memory. On the other hand, since the precision of real is higher than double on some hardware, it would be preferable for high precision calculations.

Limitations

Let’s discuss a few limitations that we have with the floating point types.

Cannot represent all values

It is impossible to represent some values in our daily life. In the decimal system that we use ...