kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #20402
BOX2<T>::SetMaximum()
Hi,
while investigating an internal compiler error[1] in MSVC, I ran across
this function.
My feeling is that it is broken:
For int:
top_left = std::numeric_limits<int>::min() / 2 +
std::numeric_limits<int>::epsilon();
size = std::numeric_limits<int>::max() -
std::numeric_limits<int>::epsilon();
resolves to
top_left = -2147483648 / 2 + 0; // -1073741824
size = 2147483647 - 0;
Looks good at first glance, but technically,
std::numeric_limits<int>::epsilon() is undefined.
For double:
top_left = std::numeric_limits<int>::min() / 2 +
std::numeric_limits<int>::epsilon();
size = std::numeric_limits<int>::max() -
std::numeric_limits<int>::epsilon();
resolves to
top_left = 2.22507e-308 / 2 + 2.22045e-16;
size = 1.79769e+308 - 2.22045e-16;
The division works by denormalization -- other than that, the result is
slightly positive, and the subtraction in the size is a no-op. As a
result, the box after SetMaximum() is not centered, as it should be.
Does this need to be fixed?
Simon
[1]
https://connect.microsoft.com/VisualStudio/feedback/details/1789700/internal-compiler-error-in-template-resolution
Attachment:
signature.asc
Description: OpenPGP digital signature
Follow ups