Skip Menu |
 

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

Report information
The Basics
Id: 21964
Status: resolved
Worked: 15 min
Priority: 0/
Queue: Math-BigInt

People
Owner: Nobody in particular
Requestors: DDICK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.77
Fixed in: 1.78



Subject: A patch to include a rounding mode of 'common'
Download (untitled) / with headers
text/plain 152b
Implements common rounding as described in http://en.wikipedia.org/wiki/Rounding. I couldn't determine an existing technique for this sort of rounding.
Subject: common_rounding.patch
diff -Naur old/lib/Math/BigInt.pm new/lib/Math/BigInt.pm --- old/lib/Math/BigInt.pm 2005-05-18 01:49:34.000000000 +1000 +++ new/lib/Math/BigInt.pm 2006-09-29 12:20:41.032497590 +1000 @@ -148,7 +148,7 @@ # These vars are public, but their direct usage is not recommended, use the # accessor methods instead -$round_mode = 'even'; # one of 'even', 'odd', '+inf', '-inf', 'zero' or 'trunc' +$round_mode = 'even'; # one of 'even', 'odd', '+inf', '-inf', 'zero', 'trunc' or 'common' $accuracy = undef; $precision = undef; $div_scale = 40; @@ -201,7 +201,7 @@ if (defined $_[0]) { my $m = shift; - if ($m !~ /^(even|odd|\+inf|\-inf|zero|trunc)$/) + if ($m !~ /^(even|odd|\+inf|\-inf|zero|trunc|common)$/) { require Carp; Carp::croak ("Unknown round mode '$m'"); } @@ -882,7 +882,7 @@ return ($self->bnan()) if defined $a && defined $p; # error $r = ${"$c\::round_mode"} unless defined $r; - if ($r !~ /^(even|odd|\+inf|\-inf|zero|trunc)$/) + if ($r !~ /^(even|odd|\+inf|\-inf|zero|trunc|common)$/) { require Carp; Carp::croak ("Unknown round mode '$r'"); } @@ -939,7 +939,7 @@ return $self->bnan() if defined $a && defined $p; $r = ${"$c\::round_mode"} unless defined $r; - if ($r !~ /^(even|odd|\+inf|\-inf|zero|trunc)$/) + if ($r !~ /^(even|odd|\+inf|\-inf|zero|trunc|common)$/) { require Carp; Carp::croak ("Unknown round mode '$r'"); } @@ -2778,7 +2778,7 @@ Math::BigInt->precision(); # get/set global P for all BigInt objects Math::BigInt->accuracy(); # get/set global A for all BigInt objects Math::BigInt->round_mode(); # get/set global round mode, one of - # 'even', 'odd', '+inf', '-inf', 'zero' or 'trunc' + # 'even', 'odd', '+inf', '-inf', 'zero', 'trunc' or 'common' Math::BigInt->config(); # return hash containing configuration =head1 DESCRIPTION @@ -3480,6 +3480,12 @@ E.g., when rounding to the first sigdig, 0.45 becomes 0.4, -0.55 becomes -0.5, but 0.4501 becomes 0.5. +=item 'common' + +round up if the digit immediately to the right of the rounding place +is 5, otherwise round down. E.g., 0.15 becomes 0.2 and 0.149 becomes +0.1 + =back The handling of A & P in MBI/MBF (the old core code shipped with Perl @@ -3672,7 +3678,7 @@ is for precision * the two rounding functions take as the second parameter one of the following rounding modes (R): - 'even', 'odd', '+inf', '-inf', 'zero', 'trunc' + 'even', 'odd', '+inf', '-inf', 'zero', 'trunc', 'common' * you can set/get the global R by using C<< Math::SomeClass->round_mode() >> or by setting C<< $Math::SomeClass::round_mode >> * after each operation, C<< $result->round() >> is called, and the result may
Subject: Re: [rt.cpan.org #21964] A patch to include a rounding mode of 'common'
Date: Mon, 9 Oct 2006 00:05:55 +0200
To: bug-Math-BigInt [...] rt.cpan.org
From: Tels <nospam-abuse [...] bloodgate.com>
Download (untitled) / with headers
text/plain 1.5k
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Moin, On Sunday 08 October 2006 23:59, via RT wrote: Show quoted text
> Sun Oct 08 17:59:42 2006: Request 21964 was acted upon. > Transaction: Ticket created by DDICK > Queue: Math-BigInt > Subject: A patch to include a rounding mode of 'common' > Broken in: 1.77 > Severity: Wishlist > Owner: Nobody > Requestors: DDICK@cpan.org > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=21964 > > > > Implements common rounding as described in > http://en.wikipedia.org/wiki/Rounding. I couldn't determine an existing > technique for this sort of rounding.
Nice, but as far as I can see, your patch only adds the name, and some doc, but no actual code to handle this case? Best wishes, Tels - -- Signed on Mon Oct 9 00:05:22 2006 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. "To get something done, a committee should consist of no more than three persons, two of them absent." -- Unknown -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iQEVAwUBRSl2Q3cLPEOTuEwVAQKspAf+KF19GPi7sSfg0hdMc+iNbf8cOHgOqFMN cDvzNu7Ail0R5LP0ZCxPROe07z+5bNKTck8N1jyIvF8HOCoXSNmtAq1VDqyVCH+W WAzLxBs78uGdqqesF2Z7j3Xxc1wVF/fwx3fp8IF1dVP4wKz+7xx++FYSJZCwnFEh UT85TSc6rlM+Id38l4NgpApkFG/fOot9jlkiW94sfXgL7hSSBiS6kmHq1A+atJ8V XqlVqQohvFd/6ueUHrF4hH2RPD0XZI6iqpsGhJmD4dEvtwxDz2AgMzMllo7pUjD3 SEqEO0VIkXk6V6eO8g0x82o7mklP1mISus4lM0ZBa0KF1h7qvm53LA== =6QHZ -----END PGP SIGNATURE-----
From: DDICK [...] cpan.org
Download (untitled) / with headers
text/plain 764b
On Sun Oct 08 18:04:13 2006, nospam-abuse@bloodgate.com wrote: Show quoted text
> Nice, but as far as I can see, your patch only adds the name, and some
doc, Show quoted text
> but no actual code to handle this case?
Ummmm. i got a bit crafty. The actual spot that i needed changing was in the bround method. The bround method defaults to rounding up and rounds down if mode eq 'trunc' (which wasn't what i wanted) OR the digit after is 1 | 2 | 3 | 4 ( which was what or wanted ) OR a set of conditions that rounded down if the digit after was 5 (which wasn't what i wanted) so basically, just by adding an additional case that dodged the initial 'trunc' case and dodged the final checks, my case was handled. i should have explained that more, but was in a bit of a rush at the time. sorry.
Thanx, applied to my local repository, will be in 1.78.
This issue has been fixed in the released v1.78. Thank you for your report, Tels


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.