develooper Front page | perl.perl6.users | Postings from August 2017

Floating point Num addition produces rationals?

Thread Next
From:
Andy Bach
Date:
August 29, 2017 17:08
Subject:
Floating point Num addition produces rationals?
Message ID:
CACV6rWJQ3QLi-dG9XGwuJRc6QSnuPVz_SAiMhdvoM5cCDA99cg@mail.gmail.com
http://www.evanmiller.org/a-review-of-perl-6.html

has

Scientific notation (such as 1e-1 for 1×10-1) always produces a
floating-point Num in Perl 6. For reasons I don’t understand, however, they
sometimes seem to add up as rationals, rather than floating-point:

> 0.1e0 + 0.2e0 == 0.3e0
False
> 1e-1 + 2e-1 == 3e-1
True

Maybe someone can explain the discrepancy to me in a polite email. Anyway,
I wholeheartedly endorse Perl 6’s use of rational numbers for exact
arithmetic, and I think more languages could benefit from a similar
implementation. For reference, Julia and Haskell have built-in rationals,
constructed (respectively) with the // and % operators; most other
languages have them as a library, if at all, without support for literals.

Is this a surprise? Is there an explanation?
-- 

a

Andy Bach,
afbach@gmail.com
608 658-1890 cell
608 261-5738 wk

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About