develooper Front page | perl.perl6.language | Postings from October 2008

Re: Smooth numeric upgrades?

From:
Darren Duncan
Date:
October 5, 2008 20:37
Subject:
Re: Smooth numeric upgrades?
Message ID:
48E987DC.2040008@darrenduncan.net
Doug McNutt wrote:
> At 18:06 +0200 10/5/08, TSa (Thomas Sandlaß) wrote:
>> Another matter is how to represent irrationals. With IEEE floats which are
>> basically non-uniformly spaced integers imprecession is involved anyway.
>> But sqrt(2) is a ratio of two infinite integers. How is that handled?

I would not consider an irrational to be a ratio of anything; rather it is 
a number that can't be expressed as a ratio of 2 integers.

> Symbolic algebra packages handle irrationals like sqrt(2) with a "root
of" function which can be included in a result before it is deliberately
converted to an approximation in a later step. Perl should NOT do things
like that.

Whether or not Perl has built-in support for symbolic math, something which 
incidentally some other general purpose languages do have afaik, any Perl 
representations of exact irrational numbers definitely should be symbolic 
in nature, that is an irrational number value is simply defined by a 
formula involving operators and rational literals, and any type 
implementing this would be neither the Int nor Rat type.

> As for unlimited precision in floats I'd rather see a floating point
number triple that includes, in its structure, an estimate of error, and
physical units.

I see that you can have both unlimited precision rationals (which is what 
floats are) that also know the error estimate and physical units; they 
would be defined in terms of an exact precision rational plus the estimate 
and units as additional attributes or metadata.

-- Darren Duncan



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