Forum: Ruby Possible bug in ruby interpreter

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
25062b6a89a7e048776a985444ac5425?d=identicon&s=25 pp (Guest)
on 2007-07-19 09:25
(Received via mailing list)
Hi there,

I found that the expression:

1*(rand (1) + 1)

will often evaluate to 0. Eliminating the space between rand and
( makes the problem go away. Is this a bug?

-pp

ruby 1.8.5 (2006-12-25 patchlevel 12) [i686-darwin8.8.2]
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2007-07-19 10:22
(Received via mailing list)
2007/7/19, pp <pedro.e.pinto@gmail.com>:
> Hi there,
>
> I found that the expression:
>
> 1*(rand (1) + 1)
>
> will often evaluate to 0. Eliminating the space between rand and
> ( makes the problem go away. Is this a bug?

I'm afraid, the bug is in your keyboard or further up the "invocation"
chain. :-)

rand (1) + 1 is parsed as rand( 1 + 1 ) which sometimes will evaluate
to 0.  Method brackets need to appear directly after the identifier.

robert
This topic is locked and can not be replied to.