Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.

Here's my test script:

#!/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"; }
Interestingly, it produced OK results ..
$ perl 11137153.pl Compare long tenth: TRUE Compare short tenth: TRUE The different is 5.55111512312578e-18. $
Sure, the difference between the values is non-zero, but comparing the individual fractions to one tenth did work.

I think it just depends on which tool you use to get the job done.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.


In reply to Re^2: Research into occasional participation in Perl/Raku development by talexb
in thread Research into occasional participation in Perl/Raku development by talexb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-25 12:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found