Skip to content

Replace MP_UNITS_CONSTEVAL with constexpr in unit operations#725

Closed
rothmichaels wants to merge 1 commit intompusz:masterfrom
rothmichaels:bugfix/runtime-inverse
Closed

Replace MP_UNITS_CONSTEVAL with constexpr in unit operations#725
rothmichaels wants to merge 1 commit intompusz:masterfrom
rothmichaels:bugfix/runtime-inverse

Conversation

@rothmichaels
Copy link
Copy Markdown
Contributor

Changes MP_UNITS_CONSTEVAL to constexpr for unit multiplication, division, and inverse operations in unit.h. This was discovered with feedback on PR #644 to use inverse.

Specifically fixes compilation error with clang (and likely other compilers?) where consteval functions cannot be called in non-constant contexts, such as:

  m_frequency = inverse<si::hertz>(period);

Added runtime tests for inverse() function covering time-to-frequency conversion, runtime parameters, and unit conversion.

Changes MP_UNITS_CONSTEVAL to constexpr for unit multiplication, division,
and `inverse` operations in unit.h.  This was discovered with feedback on
PR mpusz#644 to use `inverse`.

Specifically fixes compilation error with clang (and likely other
compilers?) where consteval functions cannot be called in non-constant
contexts, such as:

```c++
  m_frequency = inverse<si::hertz>(period);
```

Added runtime tests for `inverse()` function covering time-to-frequency
conversion, runtime parameters, and unit conversion.
@rothmichaels
Copy link
Copy Markdown
Contributor Author

I have a better idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant