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 RoundNearestTiesAway #29700

Merged
merged 2 commits into from
Nov 19, 2018
Merged

Fix RoundNearestTiesAway #29700

merged 2 commits into from
Nov 19, 2018

Conversation

simonbyrne
Copy link
Contributor

@simonbyrne
Copy link
Contributor Author

Note that this won't set the floating point status flags correctly.

y = floor(x)
ifelse(x==y,y,copysign(floor(2*x-y),x))
function round(x::T, ::RoundingMode{:NearestTiesUp}) where {T <: AbstractFloat}
copysign(floor((x + (T(0.25) - eps(T(0.5)))) + (T(0.25) + eps(T(0.5)))), x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prevfloat and nextfloat be clearer here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps: it would be

copysign(floor((x + prevfloat(T(0.25),4)) + nextfloat(T(0.25),2), x)

@simonbyrne simonbyrne force-pushed the sb/roundnearesttiesup branch from d9ab4d6 to 07449a6 Compare November 19, 2018 07:00
@simonbyrne simonbyrne force-pushed the sb/roundnearesttiesup branch from 07449a6 to 0d0834c Compare November 19, 2018 10:22
@simonbyrne simonbyrne merged commit 1c5cde2 into master Nov 19, 2018
@simonbyrne simonbyrne deleted the sb/roundnearesttiesup branch November 19, 2018 22:09
@StefanKarpinski
Copy link
Member

Backportable?

tkf pushed a commit to tkf/julia that referenced this pull request Nov 21, 2018
KristofferC pushed a commit that referenced this pull request Nov 28, 2018
Fixes #29698.

(cherry picked from commit 1c5cde2)
@KristofferC KristofferC mentioned this pull request Nov 28, 2018
61 tasks
KristofferC pushed a commit that referenced this pull request Dec 12, 2018
Fixes #29698.

(cherry picked from commit 1c5cde2)
@KristofferC KristofferC added bugfix This change fixes an existing bug and removed backport pending 1.0 labels Dec 12, 2018
KristofferC pushed a commit that referenced this pull request Feb 11, 2019
Fixes #29698.

(cherry picked from commit 1c5cde2)
KristofferC pushed a commit that referenced this pull request Feb 20, 2020
Fixes #29698.

(cherry picked from commit 1c5cde2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants