-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: RoundNearest argument for rem #10946
Conversation
And I guess this would also be useful to have for integer arguments. |
Any suggestions for why the build is breaking on 32bit? |
Tuple overhaul related. Should be fixed by 7ec501d. Either force-push or get someone who can rerun the tests to trigger it and you should be good to go. |
4ce9424
to
1b84e72
Compare
Looks really good; please continue! |
Yes, this is great. I like the design. |
@simonbyrne – this was generally well-liked, can we get it rebased and merged? |
@@ -397,6 +397,8 @@ export | |||
reim, | |||
reinterpret, | |||
rem, | |||
rem1, | |||
rem2pi, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we removed rem1, and does rem2pi need to be exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I'm not sure. I'm also not sure why rem2pi
takes a rounding argument but mod2pi
doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mod2pi(x)
is rem2pi(x, RoundDown)
Ok, I resolved the conflicts as best I could, but to be perfectly honest, I have no idea what I'm doing here. Some are pretty clear (docstring added on master right below a new definition in this PR – keep both), others were way over my head – e.g. the previous modification to |
airyai, airyaiprime, airybi, airybiprime, | ||
airyaix, airyaiprimex, airybix, airybiprimex, | ||
clamp, modf, ^, mod2pi, rem2pi, | ||
airy, airyai, airyprime, airyaiprime, airybi, airybiprime, airyx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong conflict resolution on the airy names I think
rem2pi(x::Float32, ::RoundingMode{:Nearest}) = Float32(rem2pi(Float64(x),RoundNearest)) | ||
rem2pi(x::Int32, ::RoundingMode{:Nearest}) = rem2pi(Float64(x),RoundNearest) | ||
function rem2pi(x::Int64, ::RoundingMode{:Nearest}) | ||
fx = Float64(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 space indent
885113e
to
3f0ae5c
Compare
3f0ae5c
to
b0bf8b4
Compare
Updated, but still needs some tests. |
`[-abs(y)/2, abs(y)/2]`. | ||
|
||
- if `r == RoundToZero` (default), then the result is exact, and in the interval | ||
`[0,abs(y))` if `x` is positive, or `(abs(y),0]` otherwise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe math-mode (double backtick) the intervals since that isn't Julia notation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call.
Two remaining questions:
|
x - 2π*round(x/(2π),r) | ||
|
||
without any intermediate rounding. This internally uses a high precision approximation of | ||
2π, and so will give a more `rem(x,2π,r)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a more ... accurate result than ?
be the most accurate result. | ||
|
||
- if `r == RoundToZero`, then the result is in the interval `[0,2π]` if `x` is positive,. | ||
or `[2π,0]` otherwise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[-2π,0]
?
Why is |
0.7853981633974481 | ||
``` | ||
""" | ||
mod2pi(x) = rem2pi(x,RoundDown) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@StefanKarpinski mod2pi
is now just a special case of rem2pi
I've added some tests. Comments welcome. |
Can't we just make |
I think |
rebase then merge IMO? |
might be worth adding a news entry sometime before the release |
That is not correct: mod means that the value is in [0,m) for positive m or (m,0] for negative m, I.e. that the result sign always matches the modulus; rem means that the sign matches the argument rather than the modulus. For mathematical purposes, one generally wants mod not rem. |
I took rem to mean remainder after division, as described in #9283. In that case mod is a special case (being when the division is rounded down). |
@simonbyrne and I just had the following chat conversation which cleared this issue up for me. Stefan Karpinski [2:40 PM]
Simon Byrne [2:44 PM]
Stefan Karpinski [2:59 PM]
Simon Byrne [3:00 PM]
Stefan Karpinski [3:01 PM]
Simon Byrne [3:01 PM]
Stefan Karpinski [3:01 PM]
Simon Byrne [3:01 PM]
Stefan Karpinski [3:06 PM]
Simon Byrne [3:06 PM]
Stefan Karpinski [3:06 PM]
Simon Byrne [3:08 PM]
Stefan Karpinski [3:11 PM]
Simon Byrne [3:12 PM]
Stefan Karpinski [3:13 PM]
Simon Byrne [3:13 PM]
Stefan Karpinski [3:13 PM]
Simon Byrne [3:14 PM]
Stefan Karpinski [3:14 PM]
Simon Byrne [3:15 PM]
Stefan Karpinski [3:15 PM]
Simon Byrne [3:15 PM]
Stefan Karpinski [3:16 PM]
Simon Byrne [3:17 PM]
Stefan Karpinski [3:17 PM]
Simon Byrne [3:17 PM]
Stefan Karpinski [3:18 PM]
Simon Byrne [3:18 PM]
Stefan Karpinski [3:19 PM]
Simon Byrne [3:19 PM]
Stefan Karpinski [3:19 PM]
Simon Byrne [3:19 PM]
Stefan Karpinski [3:19 PM]
Simon Byrne [3:19 PM]
Stefan Karpinski [3:20 PM]
Simon Byrne [3:20 PM]
Stefan Karpinski [3:21 PM]
Simon Byrne [3:21 PM]
Stefan Karpinski [3:21 PM]
Simon Byrne [3:21 PM]
Stefan Karpinski [3:22 PM]
Simon Byrne [3:22 PM]
Stefan Karpinski [3:23 PM]
Simon Byrne [3:23 PM]
Stefan Karpinski [3:23 PM]
Simon Byrne [3:23 PM]
Stefan Karpinski [3:24 PM]
Simon Byrne [3:24 PM]
Stefan Karpinski [3:24 PM]
Simon Byrne [3:25 PM]
Stefan Karpinski [3:26 PM]
Simon Byrne [3:27 PM]
Stefan Karpinski [3:27 PM]
Simon Byrne [3:27 PM]
Stefan Karpinski [3:28 PM]
Simon Byrne [3:28 PM]
Stefan Karpinski [3:29 PM]
Simon Byrne [3:29 PM]
Stefan Karpinski [3:29 PM]
Simon Byrne [3:30 PM]
Stefan Karpinski [3:30 PM]
Simon Byrne [3:30 PM]
Stefan Karpinski [3:30 PM]
Simon Byrne [3:30 PM]
Stefan Karpinski [3:31 PM]
Simon Byrne [3:31 PM]
Stefan Karpinski [3:31 PM]
|
* Add NEWS.md entry for three-argument rem and the new rem2pi (#10946). * Clarify precise behaviour
This is my attempt at resolving #9283. It adds an extra argument to
rem
, so thatwithout intermediate rounding, so that the result is always in the interval
[-abs(y)/2,abs(y)/2]
. This corresponds to theremainder
function in the IEEE754 spec.I've also implemented the corresponding
rem2pi
function, which is more accurate, and seems to be more useful, thanmod2pi
(I actually replaced the only 2 occurrences ofmod2pi
in Base, as this is what they were actually trying to get at).If we're happy with this, I can add some docs, tests, and implement corresponding
div
functions.