Skip Menu |

This queue is for tickets about the Math-Round CPAN distribution.

Report information
The Basics
Id: 30422
Status: rejected
Worked: 10 min
Priority: 0/
Queue: Math-Round

People
Owner: grommel [...] cpan.org
Requestors: li_xi_chen [...] hotmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Sorry to send my mail again, but it appears quite a mess on the net. I hope this one could be better
Date: Fri, 2 Nov 2007 10:26:08 +0800
To: <bug-math-round [...] rt.cpan.org>
From: 李xc <li_xi_chen [...] hotmail.com>
Dear Geoffrey Rommel and other great team members, When using your great Math::Round module, I encounter a confusing situation, the code and result is list below: ===code begins #!/usr/bin/perl use strict; use Math::Round qw(:all); my $before_nearest; my $after_nearest; foreach $before_nearest(qw/-0.31266435 -0.21620515 -0.30837255/){ chomp; print $before_nearest . "\n"; $after_nearest = nearest(0.0000001, $before_nearest); print $after_nearest . "\n\n"; } ####################### #Output is listed here: # #-0.31266435 #-0.3126643 <--- Isn't this obviously wrong? # #-0.21620515 #-0.2162052 # #-0.30837255 #-0.3083726 ####################### ===code ends My Os version; RHEL 5 x86_64 My perl version: 5.8.8 Math Round version:0.06 I hope I have made myself clear. I appreciate your effort on reading this problem and resolving this. Best regards, xichen li 2007-11-2 Show quoted text
_________________________________________________________________ Windows Live Spaces 中最年轻的成员! http://miaomiaogarden2007.spaces.live.com/
From: GROMMEL [...] cpan.org
On Thu Nov 01 22:26:31 2007, li_xi_chen@hotmail.com wrote: Show quoted text
> Dear Geoffrey Rommel and other great team members, When using > your great Math::Round module, I encounter a confusing situation, > the code and result is list below: ===code begins > #!/usr/bin/perl use strict; > use Math::Round qw(:all); my $before_nearest; my > $after_nearest; foreach $before_nearest(qw/-0.31266435 > -0.21620515 -0.30837255/){ chomp; print $before_nearest . > "\n"; $after_nearest = nearest(0.0000001, $before_nearest); > print $after_nearest . "\n\n"; } ####################### > #Output is listed here: # #-0.31266435 #-0.3126643 > <--- Isn't this obviously wrong? # #-0.21620515 #- > 0.2162052 # #-0.30837255 #-0.3083726 > ####################### ===code ends My Os version; RHEL 5 > x86_64 My perl version: 5.8.8 Math Round version:0.06 I > hope I have made myself clear. I appreciate your effort on reading > this problem and resolving this. Best regards, xichen li 2007-11-2 > > > _________________________________________________________________ > Windows Live Spaces 中最年轻的成员! > http://miaomiaogarden2007.spaces.live.com/
Thanks for your note. You have run into an unavoidable consequence of using floating-point numbers: the results will not always be quite what you expect. See the standard floating-point disclaimer in the POD. If getting -0.3126644 in the above case is important to you, set $Math::Round::half to a slightly larger value. 再见
See reply on rt.cpan.org.