Skip Menu |

This queue is for tickets about the Number-Fraction CPAN distribution.

Report information
The Basics
Id: 55329
Status: resolved
Priority: 0/
Queue: Number-Fraction

People
Owner: DAVECROSS [...] cpan.org
Requestors: mwang [...] unixlabplus.com
Cc:
AdminCc:

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



Subject: Request for enhancement on Number::Fraction
Date: Sat, 6 Mar 2010 07:51:35 -0500
To: dave [...] mag-sol.com
From: Michael Wang <mwang [...] unixlabplus.com>
Dave, Can you enhance your module to include ** operation? Example: 1/2 ** 3 = 1/8 Thanks. -- Michael Wang, http://www.unixlabplus.com/, /* for future expansion */ Email=$(echo 37wxloc@ibmude.au | sed "s:\(.\)\(.\)\(.\)\(.\):\4\3\2\1:g") Technical writings: http://www.unixlabplus.com/unix-prog/Publication.txt
On Mon Mar 08 04:03:12 2010, mwang@unixlabplus.com wrote: Show quoted text
> Dave, > > Can you enhance your module to include ** operation? Example: > > 1/2 ** 3 = 1/8
Michael, I'm really unlikely to have the time to add this for a couple of months. But if you wanted it done, then I'd be really happy to accept patches. The source code is on github at: http://github.com/davorg/number-fraction At the very least, if you wrote some (failing) tests, then I'd hav ean idea of where to start. Cheers, Dave...
On Mon Mar 08 04:13:15 2010, DAVECROSS wrote: Show quoted text
> On Mon Mar 08 04:03:12 2010, mwang@unixlabplus.com wrote:
> > Dave, > > > > Can you enhance your module to include ** operation? Example: > > > > 1/2 ** 3 = 1/8
> > Michael, > > I'm really unlikely to have the time to add this for a couple of > months. But if you wanted it done, then I'd be really happy to accept > patches. The source code is on github at: > > http://github.com/davorg/number-fraction > > At the very least, if you wrote some (failing) tests, then I'd hav ean > idea of where to start.
Michael, This evening I thought I'd try to add some tests for exponentiation to the distribution, just to get a feel for how much work might be involved to implement this feature. You can see the test program at: http://github.com/davorg/number-fraction/blob/master/t/13_exp.t I'm very happy to report that the tests all passed without me having to change the code at all. So it looks like the module already supports the operation you want. I suppose Perl is faking it from the multiplication support. Please try the existing CPAN version and see what you think. If it's not working for you in some way, then please send some failing tests so that I can investigate further. Cheers, Dave...
Subject: Re: [rt.cpan.org #55329] Request for enhancement on Number::Fraction
Date: Mon, 15 Mar 2010 23:17:33 -0400
To: DAVECROSS via RT <bug-Number-Fraction [...] rt.cpan.org>
From: Michael Wang <mwang [...] unixlabplus.com>
On Mon, Mar 15, 2010 at 05:59:08PM -0400, DAVECROSS via RT wrote: Show quoted text
> Michael, > > This evening I thought I'd try to add some tests for exponentiation to > the distribution, just to get a feel for how much work might be involved > to implement this feature. You can see the test program at: > > http://github.com/davorg/number-fraction/blob/master/t/13_exp.t > > I'm very happy to report that the tests all passed without me having to > change the code at all. So it looks like the module already supports the > operation you want. I suppose Perl is faking it from the multiplication > support. > > Please try the existing CPAN version and see what you think. If it's not > working for you in some way, then please send some failing tests so that > I can investigate further. > > Cheers,
Hi Dave ... I saw your test. I think I did not make myself clear in what I am requesting. I want the result appear as fractional. For example, I want: 1/2 ** 3 => 1/8 not 0.125 The following is "failed" test: ==> cut here <== use Number::Fraction ':constants'; my $f = '1/2'; my $power = '3'; my $answer = $f ** $power; print "$answer\n"; ==> cut here <== $ perl frac2.pl 0.125 I understand the power is fractional, for example, 2**(1/2) can not be expressed by a fractional. I only want fractional answer when power is an integer. I think the answer can be simply expressed as (a/b)**c = a**c/b**c that would be fractional format. The other thing I noticed is the final fraction is expressed in "non-reduced" form, like, 9/8. I wrote a trivial subroutine to convert it to "reduced" format. Example: 9/8 => 1 1/8. I think it is best to add an option: some people wants reduced format, some don't. sub reduce { my $input = shift; return $input unless $input =~ m{ ^ (-|\+)? (\d+) / (\d+) $}x; my $sign = $1 || ""; my $a = $2; my $b = $3; my $c = 0; while ( $a > $b ) { $a = $a - $b; $c++; } if ( $c == 0 ) { return "${sign}$a/$b"; } else { return "${sign}$c $a/$b"; } } -- Michael Wang
This request was fixed in Number::Fraction 1.13 which was released to CPAN some months ago.