Welcome to the world of floating point accuracy.

This little program typically ends within 100 iterations for me:

$ 6 'my int $a = 0; $a++ while (1..^(1+10e-15)).rand < 1+10e-15; say $a’
96

Either we dismiss this bug as being caused by lack of floating point accuracy, 
or we build in something special in .rand for Num Ranges that will make sure 
that the returned value actually is less then upper range as indicated by “<“.

I would mark this RT as a @LARRY case.

> On 27 Aug 2016, at 08:31, Itsuki Toyota (via RT) 
> <perl6-bugs-follo...@perl.org> wrote:
> 
> # New Ticket Created by  Itsuki Toyota 
> # Please include the string:  [perl #129104]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=129104 >
> 
> 
> See the following result
> 
> $ perl6 -e '(1..^(1+10e-15)).rand.say'
> 1.00000000000001
> 
> $ perl6 -e 'say 1.00000000000001 - (1+10e-15)'
> 0
> 
> $ perl6 -e '(1..^(1+10e-15)).excludes-max.say'
> True
> 
> I think that the 1st example it shouldn't return 1+10e-15, since 
> Range.excludes-max is True.
> 
> My Perl 6 version is
> $ perl6 --version
> This is Rakudo version 2016.07.1-199-gdd9b760 built on MoarVM version 
> 2016.07-17-g40948f6
> implementing Perl 6.c.

Reply via email to