note
talexb
<p>Moving on to fractions, when I heard that raku was going to deal with fractions in a clever way, I decided to experiment and write my own module to do fractions. Instead of adulting tonight, I decided to spend a little time fiddling with code.
</p>
<p>Here's my test script:
<code>
#!/usr/bin/perl
use strict;
use warnings;
# OK, try the division of the large numbers using my
# Number::MyFraction module. No idea what result I'll get.
use lib '../Number-MyFractions/lib';
use Number::MyFraction;
{
my $long_tenth =
Number::MyFraction->new( 3602879701896397, 36028797018963968 );
my $short_tenth = Number::MyFraction->new( 1, 10 );
my $difference = $long_tenth - $short_tenth;
print "Compare long tenth: "
. ( $long_tenth->decimal_val == .1 ? 'TRUE' : 'FALSE' ) . "\n";
print "Compare short tenth: "
. ( $short_tenth->decimal_val == .1 ? 'TRUE' : 'FALSE' ) . "\n";
print "The different is " . $difference->decimal_val . ".\n";
}
</code>
Interestingly, it produced OK results ..
<code>
$ perl 11137153.pl
Compare long tenth: TRUE
Compare short tenth: TRUE
The different is 5.55111512312578e-18.
$
</code>
Sure, the difference between the values is non-zero, but comparing the individual fractions to one tenth did work.
</p>
<p>
I think it just depends on which tool you use to get the job done.
</p>
<div class="pmsig"><div class="pmsig-131279">
<p>Alex / [talexb] / Toronto</p>
<p><small>Thanks PJ. We owe you so much. <a href="http://www.groklaw.net">Groklaw</a> -- RIP -- 2003 to 2013.</small></p>
</div></div>
11137153
11137168