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

Re: The Inf type

Thread Previous | Thread Next
From:
TSa
Date:
June 3, 2008 03:57
Subject:
Re: The Inf type
HaloO,

John M. Dlugosz wrote:
> I don't know why he's calling it an "Int with non-uniform spacing" 
> unless he is complaining about what happens when you store ints in 
> floats: it rounds off to the mantissa size.

With uniform spacing you have

   constant $step = 1;

and

   $x++;  # means $x = $x + $step

whereas non-uniform is

   $x++;  # means $x = $x + $x.step;

You can make the second to subsume the first with

   multi method *step (Int) { 1 }

and optimize whenever you can prove that $x always
does Int. If you can't, you leave that to the runtime.

Going further with that you could define $a == $b to
actually mean abs($a-$b) < min($a.step, $b.step).
E.g. with the usual 64bit floats you have 0.5.step==2**-53
and (2**52).step==1. Then per definition

   multi method *step (Real) { 0 }

essentially means a real object can't step away from itself
or some such.

Given the above, the optimizer can e.g. take a sub that claims to
achieve its business with two Reals in such a way that ++ is
considered a noop and taken out of the code. If the code is not
up to that it can hardly be a function that properly handles two
Reals. If your test suite manages to detect that failure is another
question. But a good enough optimizer makes bad enough programs
reveal their realness or lack thereof ;)


Regards, TSa.
-- 

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

Thread Previous | Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About