File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -175,12 +175,16 @@ =head2 Round
175175
176176 Round(1.789,2) returns 1.79
177177
178+ Before rounding, the environment variable numZeroLevelTolDefault is added to a number (or subtracted
179+ from a number if that number is negative). This is done to combat machine rounding error where
180+ somthing like 1.5 has become 1.4999999999999997.
181+
178182=cut
179183
180- # Round contributed bt Mark Schmitt 3-6-03
181184sub Round {
182- if (@_ == 1) { $_ [0] > 0 ? int $_ [0] + 0.5 : int $_ [0] - 0.5 }
183- elsif (@_ == 2) { $_ [0] > 0 ? Round($_ [0] * 10**$_ [1]) / 10**$_ [1] : Round($_ [0] * 10**$_ [1]) / 10**$_ [1] }
185+ my $x = $_ [0] > 0 ? $_ [0] + $envir {numZeroLevelTolDefault } : $_ [0] - $envir {numZeroLevelTolDefault };
186+ if (@_ == 1) { $x > 0 ? int $x + 0.5 : int $x - 0.5 }
187+ elsif (@_ == 2) { $x > 0 ? Round($x * 10**$_ [1]) / 10**$_ [1] : Round($x * 10**$_ [1]) / 10**$_ [1] }
184188}
185189
186190=head2 lcm
You can’t perform that action at this time.
0 commit comments