std::numeric_limits<fp>::min() vs. lowest()
Klummel69 opened this issue · 2 comments
According to https://en.cppreference.com/w/cpp/types/numeric_limits
min() and lowest() return different values for floating point types:
min():
Returns the minimum finite value representable by the numeric type T.
For floating-point types with denormalization, min() returns the minimum positive normalized value.
Note that this behavior may be unexpected, especially when compared to the behavior of min() for integral types._
fpm min() and lowest() return the same value (smallest negative number).
In my opinion, fpm min() should behave more like floating point min() here.
Is there a reason why min() is implemented this way?
Who can read...
Sorry, now I get it.
Indeed. To be clear (and for future readers), fpm's fixed-point type behaves like a floating-point type without denormalization so according to the letter of the spec, the floating-point rule for min()
doesn't apply.
You could argue about the spirit of the spec and that fpm is supposed to pretend to be a float
, but it seems that the reason the rule exists is to let users know when to expect a loss of precision when moving from normal into subnormal floating-point numbers. With fpm, you don't have this problem and you always have to be wary of precision when compared to floats.