Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Fraction Cancelation [Perl6]

by u65 (Chaplain)
on Feb 24, 2016 at 20:31 UTC ( #1156069=note: print w/replies, xml ) Need Help??


in reply to Fraction Cancelation

Since Perl 6 has good handling of rational numbers, perhaps looking at its guts would help.

Using Perl 6 one could use the OP's arrays to do this:

#!/usr/bin/env perl6 my @a = <1 4 6 2 7 87 5 6 4 32>; my @b = <86 50 62 41 32>; my $a = [*] @a; my $b = [*] @b; say "Product of array \@a = $a"; say "Product of array \@b = $b"; # generate an arbitrary precision rational number: my $c = FatRat.new($a, $b); say "Real \$c: $c"; say "Rational \$c: { $c.numerator } / { $c.denominator }";

Output

Product of array @a = 112250880 Product of array @b = 349779200 Real $c: 0.3209193 Rational $c: 87696 / 273265

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1156069]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2021-04-20 23:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?