Ruby 1.8.6 : 0.5 == 5.0 ???

  • Thread starter Thomas Sevestre
  • Start date
T

Thomas Sevestre

Hello,

I have a strange problem on one of my servers.
I just installed ruby 1.8.6 from source :

/tmp/ruby-1.8.6-p383$uname -a
Linux prod2-ctxctrl 2.6.32-24-generic-pae #39-Ubuntu SMP Wed Jul 28
07:39:26 UTC 2010 i686 GNU/Linux

/tmp/ruby-1.8.6-p383$ruby --version
ruby 1.8.6 (2009-08-04 patchlevel 383) [i686-linux]

Something is broken with floats, here are a few tests :

/tmp/ruby-1.8.6-p383$ruby -e "puts 0.5"
5.0
/tmp/ruby-1.8.6-p383$ruby -e "puts 0.05"
5.0
/tmp/ruby-1.8.6-p383$ruby -e "puts 0.5 == 5.0"
true
/tmp/ruby-1.8.6-p383$ruby -e "puts 1.0 / 2"
0.5

Do you have any idea of what is going on?

Thanks
Thomas
 
P

Peter Hickman

This seems to work for me for my version and os etc.

ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.0.0]
$ ruby -e "puts 0.5 == 5.0"
false
$
 
H

Heesob Park

Hi,

2010/9/1 Thomas Sevestre said:
Hello,

I have a strange problem on one of my servers.
I just installed ruby 1.8.6 from source :

/tmp/ruby-1.8.6-p383$uname -a
Linux prod2-ctxctrl 2.6.32-24-generic-pae #39-Ubuntu SMP Wed Jul 28 07:39:26
UTC 2010 i686 GNU/Linux

/tmp/ruby-1.8.6-p383$ruby --version
ruby 1.8.6 (2009-08-04 patchlevel 383) [i686-linux]

Something is broken with floats, here are a few tests :

/tmp/ruby-1.8.6-p383$ruby -e "puts 0.5"
5.0
/tmp/ruby-1.8.6-p383$ruby -e "puts 0.05"
5.0
/tmp/ruby-1.8.6-p383$ruby -e "puts 0.5 == 5.0"
true
/tmp/ruby-1.8.6-p383$ruby -e "puts 1.0 / 2"
0.5

Do you have any idea of what is going on?
This is a gcc version issue with gcc 4.4.1.

Refer to http://www.ruby-forum.com/topic/199860

Regards,
Park Heesob
 
K

Kirk Haines

Hello,

I have a strange problem on one of my servers.
I just installed ruby 1.8.6 from source :

/tmp/ruby-1.8.6-p383$uname -a
Linux prod2-ctxctrl 2.6.32-24-generic-pae #39-Ubuntu SMP Wed Jul 28 07:39:26
UTC 2010 i686 GNU/Linux

/tmp/ruby-1.8.6-p383$ruby --version
ruby 1.8.6 (2009-08-04 patchlevel 383) [i686-linux]

Something is broken with floats, here are a few tests :

/tmp/ruby-1.8.6-p383$ruby -e "puts 0.5"
5.0
/tmp/ruby-1.8.6-p383$ruby -e "puts 0.05"
5.0
/tmp/ruby-1.8.6-p383$ruby -e "puts 0.5 == 5.0"
true
/tmp/ruby-1.8.6-p383$ruby -e "puts 1.0 / 2"
0.5

Do you have any idea of what is going on?

GCC. The version of GCC that you built with does fun and entertaining
things with floating point numbers in the p383 (and many other patch
levels of 1.8.6 and 1.8.7) source. Try pulling from SVN and building
that one:

svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6

Let me know if you still experience the bizarre floating point behavior.


Kirk Haines
 
T

Thomas Sevestre

Le 1 sept. 10 =E0 15:27, Heesob Park a =E9crit :
Hi,

2010/9/1 Thomas Sevestre said:
Hello,

I have a strange problem on one of my servers.
I just installed ruby 1.8.6 from source :

/tmp/ruby-1.8.6-p383$uname -a
Linux prod2-ctxctrl 2.6.32-24-generic-pae #39-Ubuntu SMP Wed Jul 28 =20=
07:39:26
UTC 2010 i686 GNU/Linux

/tmp/ruby-1.8.6-p383$ruby --version
ruby 1.8.6 (2009-08-04 patchlevel 383) [i686-linux]

Something is broken with floats, here are a few tests :

/tmp/ruby-1.8.6-p383$ruby -e "puts 0.5"
5.0
/tmp/ruby-1.8.6-p383$ruby -e "puts 0.05"
5.0
/tmp/ruby-1.8.6-p383$ruby -e "puts 0.5 =3D=3D 5.0"
true
/tmp/ruby-1.8.6-p383$ruby -e "puts 1.0 / 2"
0.5

Do you have any idea of what is going on?
This is a gcc version issue with gcc 4.4.1.

Refer to http://www.ruby-forum.com/topic/199860

Regards,
Park Heesob


This is it!

Thanks,
Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top