Add Irrational support to rem2pi #43539
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds
Irrationalsupport torem2piand thus fixes #42799. One thing that is a bit awkward is thatrem2pi(π, r)returnsπin the form of anIrrationalfor each rounding mode exceptRoundUp, where it instead returns theFloat64equivalent of-π. I don't expect this will lead to type instability in practice, as typically the rounding mode is fixed in the code and is thus known at compile time.I also added a version that accepts any
Real, so that e.g. the exponential constant ℯ can be passed. Admittedly, I don't see any real use case for calling with that constant in particular, but at least it works as expected now, and there are likely other, more useful, cases that will benefit from this. It also follows the practice of other methods (e.g.sin,cos), which do indeed accept this constant by converting it to afloat. While making this change, I also changed the existing method specializing onInt64to specialize onIntegerinstead, as that method will work for anyIntegerthat can be exactly converted to aFloat64, whether it is anInt16,Int32,Int64, or even aBigInt.