[mercury-users] Perl implementation of Rational numbers (documentation)

Richard A. O'Keefe ok at atlas.otago.ac.nz
Fri May 4 09:58:57 AEST 2001


Terrence Brannon <princepawn at earthlink.net> wrote:
	NAME
	    Rational - Perl extension for manipulating rational numbers
	
...

It was not clear to me whether this was a manual page for a package
that already exists, or a sample of what it would look like.  If the
package already exists, what are the names of the other operations?

If it's a sample for discussion, then
	      my $r1 = Rational->new(numerator=>1, denominator=>3);

suggests to me that for many uses

	my $r1 = Rational::from("1/3")

would be better.  Amongst other things, rational numbers using bounded
integers are next door to useful.  I wrote a rational number package
in Burroughs Algol back in the mid 70s.  The B6700 could do integer
arithmetic on 78-bit + sign integers, so it was amazing how often my
calculations on rational matrices worked.  But it was also amazing
how often they didn't.  There are four approaches to handling integers
that are too big to fit in machine words:
  - The Burroughs Algol approach:  raise an exception so that you KNOW
    you're getting wrong answers.
  - The C approach: quietly give devastatingly wrong answers.  (This is
    optional in C, explicitly required in Java.)
  - The Perl approach: quietly give subtly wrong answers so that their
    wrongness only shows up much later.
  - The Lisp approach: give the RIGHT answer all the time.

A rational arithmetic package based on unsound integer arithmetic is
of very limited usefulness, whatever the programming language.

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list