I agree. I'll add a note to the docs.

Vincent


On Mon, 17 Apr 2017 16:16:49 -0500,
Tim Jervis wrote:
> 
> I like the document route; anyone who is happy with the performance tradeoff 
> would be free to implement a more conservative version.
> 
> On 17 Apr 2017, at 21:59, Ben Greenman <[email protected]> wrote:
> 
>  Maybe, just add a note to the docs?
> 
>  On Mon, Apr 17, 2017 at 4:56 PM, Vincent St-Amour 
> <[email protected]> wrote:
> 
>  The latter is easy to fix; I've submitted a pull request.
> 
>  The former is trickier. The problem is not so much due to the step size
>  itself, but rather to a combination of the step size and of a particular
>  iteration state.
> 
>  (For people following along, the issue is that there exists a value `x`
>  such that `(= (+ x 1e-17) x)`, and that the iteration reaches that `x`
>  as its state at some point, then loops.)
> 
>  Guarding against that would require an additional check at each
>  iteration, which may introduce overhead.
> 
>  I did some very, very crude benchmarking, and here's what I got:
> 
>  Without extra check:
>  > (time (for ([i (in-range 10000000000)]) i))
>  cpu time: 19478 real time: 19469 gc time: 0
>  > (time (for ([i (in-range 10000000000)]) i))
>  cpu time: 20171 real time: 20179 gc time: 0
>  > (time (for ([i (in-range 10000000000)]) i))
>  cpu time: 20049 real time: 20043 gc time: 0
> 
>  With extra check:
>  > (time (for ([i (in-range 10000000000)]) i))
>  cpu time: 22100 real time: 22210 gc time: 0
>  > (time (for ([i (in-range 10000000000)]) i))
>  cpu time: 22227 real time: 22265 gc time: 0
>  > (time (for ([i (in-range 10000000000)]) i))
>  cpu time: 21934 real time: 22016 gc time: 0
> 
>  The difference is non-insignificant. Admittedly, this is the worst
>  possible case, though.
> 
>  Vincent
> 
>  On Mon, 17 Apr 2017 09:17:32 -0500,
>  Tim Jervis wrote:
>  >
>  > Dear Racket Users,
>  >
>  > I’ve noticed the following procedure calls don’t return (on my 64 bit Mac 
> hardware):
>  >
>  > 1 (range (- 1 1e-16) 1.0 1e-17)
>  > 2 (range 0 1 0)
>  >
>  > While (2) is obvious, (1) tripped me up (as I hadn’t noticed my step size 
> had fallen to effectively zero).
>  >
>  > A small tweak to for.rkt in the racket distribution could trap the 
> condition of an actually or effectively zero step. for.rkt already traps the 
> condition where step is not real.
>  >
>  > If this makes sense, could one of the authors consider adding the tweak? 
> Or is there a reason for leaving it alone?
>  >
>  > Kind regards,
>  >
>  > Tim
>  >
>  > Tim Jervis
>  >
>  > http://timjervis.com/
>  >
>  > --
>  > You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
>  > To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
>  > For more options, visit https://groups.google.com/d/optout.
> 
>  --
>  You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
>  To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
>  For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to