Skip Menu |

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

Report information
The Basics
Id: 107143
Status: open
Priority: 0/
Queue: Math-Round

People
Owner: Nobody in particular
Requestors: jellisii [...] gmail.com
Cc:
AdminCc:

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



round_even doesn't behave as expected. example code: use strict; use warnings; use Math::Round qw(round_even); use v5.16; # numbers are actual numbers that I use to do math on video geometry # I'm having to upscale some video to match other geometry. # MP4 requires height and width be divisible by 2. my $h1 = 480; my $h2 = 368; my $w = 640; my $ratio = $h1/$h2; my $upscaled_w = $w * $ratio; say "Raw upscale is $upscaled_w"; my $rounded = round_even($upscaled_w); say "Rounded upscale is $rounded";
On Thu Sep 17 09:06:35 2015, jellisii wrote: Show quoted text
> round_even doesn't behave as expected. example code: > use strict; > use warnings; > use Math::Round qw(round_even); > use v5.16; > > # numbers are actual numbers that I use to do math on video geometry > # I'm having to upscale some video to match other geometry. > # MP4 requires height and width be divisible by 2. > my $h1 = 480; > my $h2 = 368; > my $w = 640; > > my $ratio = $h1/$h2; > > my $upscaled_w = $w * $ratio; > say "Raw upscale is $upscaled_w"; > my $rounded = round_even($upscaled_w); > say "Rounded upscale is $rounded";
Above code, on my system, returns the following: Raw upscale is 834.782608695652 Rounded upscale is 835. I expect it to return 836, not 835. If the intention of the function is to only exclusively round .5 values to an even value, then this may be working as intended and I apologize for wasting your time. eellis@tc01:~/convert_e360$ perl -v This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi (with 41 registered patches, see perl -V for more detail)
On Thu Sep 17 09:24:55 2015, jellisii wrote: Show quoted text
> On Thu Sep 17 09:06:35 2015, jellisii wrote:
> > round_even doesn't behave as expected. example code: > > use strict; > > use warnings; > > use Math::Round qw(round_even); > > use v5.16; > > > > # numbers are actual numbers that I use to do math on video geometry > > # I'm having to upscale some video to match other geometry. > > # MP4 requires height and width be divisible by 2. > > my $h1 = 480; > > my $h2 = 368; > > my $w = 640; > > > > my $ratio = $h1/$h2; > > > > my $upscaled_w = $w * $ratio; > > say "Raw upscale is $upscaled_w"; > > my $rounded = round_even($upscaled_w); > > say "Rounded upscale is $rounded";
> > Above code, on my system, returns the following: > Raw upscale is 834.782608695652 > Rounded upscale is 835. > > I expect it to return 836, not 835. > > If the intention of the function is to only exclusively round .5 > values to an even value, then this may be working as intended and I > apologize for wasting your time. > > eellis@tc01:~/convert_e360$ perl -v > > This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64- > linux-gnu-thread-multi > (with 41 registered patches, see perl -V for more detail)
I misspoke previously when I said "I expect it to return 836, not 835". That should be "I expect it to return 834 or 836, not 835."
Subject: Re: [rt.cpan.org #107143] round_even does not appear to work as advertised.
Date: Thu, 17 Sep 2015 10:12:56 -0500
To: bug-Math-Round [...] rt.cpan.org
From: Geoffrey Rommel <wgrommel [...] gmail.com>
The intent of round_even is indeed to round to the even number only when the value ends with .5. Perhaps nearest(2, $upscaled_w) would yield the desired result. On Thu, Sep 17, 2015 at 8:35 AM, Eric Ellis via RT < bug-Math-Round@rt.cpan.org> wrote: Show quoted text
> Queue: Math-Round > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=107143 > > > On Thu Sep 17 09:24:55 2015, jellisii wrote:
> > On Thu Sep 17 09:06:35 2015, jellisii wrote:
> > > round_even doesn't behave as expected. example code: > > > use strict; > > > use warnings; > > > use Math::Round qw(round_even); > > > use v5.16; > > > > > > # numbers are actual numbers that I use to do math on video geometry > > > # I'm having to upscale some video to match other geometry. > > > # MP4 requires height and width be divisible by 2. > > > my $h1 = 480; > > > my $h2 = 368; > > > my $w = 640; > > > > > > my $ratio = $h1/$h2; > > > > > > my $upscaled_w = $w * $ratio; > > > say "Raw upscale is $upscaled_w"; > > > my $rounded = round_even($upscaled_w); > > > say "Rounded upscale is $rounded";
> > > > Above code, on my system, returns the following: > > Raw upscale is 834.782608695652 > > Rounded upscale is 835. > > > > I expect it to return 836, not 835. > > > > If the intention of the function is to only exclusively round .5 > > values to an even value, then this may be working as intended and I > > apologize for wasting your time. > > > > eellis@tc01:~/convert_e360$ perl -v > > > > This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64- > > linux-gnu-thread-multi > > (with 41 registered patches, see perl -V for more detail)
> > I misspoke previously when I said "I expect it to return 836, not 835". > That should be "I expect it to return 834 or 836, not 835." > > >