Is there a constexpr alternative to modf

Viewed 130

I would like to get the integer and the fractional part of a float. This is easy with std::modf but the function is not constexpr. What is the reason for this and what is the alternative?

1 Answers

Is there a constexpr alternative to modf

There is no standard constexpr alternative to modf or related math functions.

but the function is not constexpr. What is the reason for this

Those functions pre-exist constexpr. They even pre-exist C++. As such, when those founctions were specified, they couldn't have been constexpr.

There are no standard constexpr alternatives because such proposal hasn't been accepted into the standard. Such change has been proposed, so this may potentially change in a future standard: P1383

what is the alternative?

Wait for the potential future standard, or do the math without using standard functions.

Related