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

Round() function #403

Open
Alex-Jordan opened this issue Mar 13, 2019 · 0 comments
Open

Round() function #403

Alex-Jordan opened this issue Mar 13, 2019 · 0 comments

Comments

@Alex-Jordan
Copy link
Contributor

PGauxiliaryFunctions.pl has the function Round(x,n). It doesn't always work as you'd want it to. This is understandable, given rounding issues with floating point.

When floating point rounding errors accumulate in just the right way, they can move something like 0.5 to 0.4999...9 or similar. I am seeing that as an issue with:

$x = 3.3625/0.025;
$rounded = Round($x,0);
TEXT("When you round $x you get $rounded.");

with seed 4098 (if that even matters) which outputs

When you round 134.5 you get 134

In defaults.conf, there is numZeroLevelDefault => 1E-14. Would there be any objection to me redefining Round() to make use of this? One way to characterize what I would do is to add this to a number before rounding. So if it were internally 0.499999999999992, then it would become 0.500000000000002 and then get rounded to 1. It would be an approach that assumes something like 0.499999999999992 is really supposed to be 0.5, but rounding error crept in.

Everything I said would be adjusted if not rounding to a whole number.

Alternatively I could make a new subroutine with a different name.

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

No branches or pull requests

1 participant