Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Overflow in comparison ops #614

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/static/international_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ using namespace mp_units::international::unit_symbols;

// Mass
static_assert(100'000'000 * isq::mass[lb] == 45'359'237 * isq::mass[si::kilogram]);
// 47 * 45'359'237 = 2'131'884'139 = 0x7F11'F86B; the largest value that fits a signed int32 in this comparison
// 47 * 100'000'000 = 4'700'000'000 = 0x1'1824'4F00 will be truncated to 0x1824'4F00.
static_assert(47 * isq::mass[lb] < 47 * isq::mass[si::kilogram]);
// 10^14 easily fits into int64 (which has about a range 10^19); but converted to the gcd, it doesn't!
static_assert(100'000'000'000'000 * isq::mass[lb] == 45'359'237'000'000 * isq::mass[si::kilogram]);
static_assert(1 * isq::mass[lb] == 16 * isq::mass[oz]);
static_assert(1 * isq::mass[oz] == 16 * isq::mass[dr]);
static_assert(7'000 * isq::mass[gr] == 1 * isq::mass[lb]);
Expand Down
Loading