Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Fraction Cancelation [Perl6]

by u65 (Chaplain)
on Feb 24, 2016 at 20:31 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1156069]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-20 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found