develooper Front page | perl.perl6.compiler | Postings from September 2011

[perl #69182] [BUG] Ugly interaction between Rat objects and integer overflow

Thread Previous
From:
Will Coleda via RT
Date:
September 19, 2011 21:03
Subject:
[perl #69182] [BUG] Ugly interaction between Rat objects and integer overflow
Message ID:
rt-3.6.HEAD-31297-1316491428-763.69182-15-0@perl.org
On Fri Apr 30 07:57:00 2010, bbkr wrote:
> This returns NAN now (in my case on 1024th operation)
> 
> 
> perl6 -e 'my $d = 2; my $p = 1; for 1..1024 { print "operation $_: ";
> say $p *= ($d-1)/($d); $d *= 2 }'
> 
> operation 1017: 0.288788095086602
> operation 1018: 0.288788095086602
> operation 1019: 0.288788095086602
> operation 1020: 0.288788095086602
> operation 1021: 0.288788095086602
> operation 1022: 0.288788095086602
> operation 1023: 0.288788095086602
> operation 1024: NaN

Here's my current run:
$ ./perl6 -e 'my $d = 2; my $p = 1; while 1 { say $p *= ($d-1)/($d); $d *= 2 }'
0.5
0.375
0.328125
0.3076171875
0.298004150390625
0.293347835540771
0.291056055575609
0.289919117858517
0.28935286958145
0.289070298419749
Inf
...
Inf
Floating point exception
$ echo $?
136

-- 
Will "Coke" Coleda

Thread Previous


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