Re:C++20 Concepts: The Definitive Guide
by ncmncm on Sunday August 22, 2021 @03:40PM
(#28268796)
They are distinct values but they compare equal. For almost all uses they are effectively equal, except where you are producing infinities.
[ Parent
| on HN ]
Re:C++20 Concepts: The Definitive Guide
by CogitoCogito on Sunday August 22, 2021 @03:46PM
(#28268857)
I hadn't thought about the infinities part. If they had the same behavior in all operations involving other numbers, then I could see how they could nonetheless be the same from a C++ type perspective, but given they behave differently, C++ certainly couldn't consider them the same.
Thanks for clearing that up!
If you keep infinities and NaNs out of a subsystem, then float and double are totally ordered within that subsystem. So, it is a choice. I would not hesitate on that basis.
Of more moment is that floating point variables often represent imprecise values, such that e.g. 1.41 could represent a value that should equal another transcribed as 1.39. The type system will not help you there. You are obliged to code in tolerance the hard way.