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

Fix units::modf() for scaled quantities with a frac part #312

Open
wants to merge 1 commit into
base: v3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion include/units/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3654,7 +3654,7 @@ namespace units
dimensionless<typename dimensionlessUnit::underlying_type> modf(const dimensionlessUnit x, dimensionlessUnit* intpart) noexcept
{
typename dimensionlessUnit::underlying_type intp;
dimensionlessUnit fracpart = std::modf(x.template to<decltype(intp)>(), &intp);
dimensionlessUnit fracpart = dimensionless<>{std::modf(x.template to<decltype(intp)>(), &intp)};
*intpart = intp;
return fracpart;
}
Expand Down
6 changes: 6 additions & 0 deletions unitTests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4642,6 +4642,12 @@ TEST_F(UnitMath, modf)
double umodfr1;
decltype(uval) umodfr2;
EXPECT_EQ(std::modf(uval.to<double>(), &umodfr1), units::modf(uval, &umodfr2));
EXPECT_EQ(umodfr1, umodfr2);
percent<> pval{202.5};
double pmodfr1;
decltype(pval) pmodfr2;
EXPECT_EQ(std::modf(pval.to<double>(), &pmodfr1), units::modf(pval, &pmodfr2));
EXPECT_EQ(pmodfr1, pmodfr2);
}

TEST_F(UnitMath, exp2)
Expand Down