# Unintentional hype of Ruby irb and ri

**URL:** <https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253>\
**Category:** ruby-talk\
**Created:** [30 March 2006 17:33 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253 "2006-03-30T17:33:43Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Tashiro](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@Stephen\_Tashiro](https://rubytalk.org/u/Stephen_Tashiro)\
**Post date:** [30 March 2006 17:33 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/1 "2006-03-30T17:33:43Z")

</div>

Perhaps an inflamatory title - but it answers some simple questions.

Having looked at the Pixaxe book and visited various websites with Ruby  
tutorials, I think there is an unintentional hype of certain Ruby  
features. We may blame this on the distributors of software. For  
example, the authors tell us how easy it is to use irb. On my Redhat  
Enterprise Linux machine, ruby puts("Hello World") ran fine. But irb  
was not a command known to bash. The redhat distribution has the  
packages:  
ruby-docs-1.8.1-7.EL4.2  
ruby-tcltk-1.8.1-7.EL4.2  
ruby-1.8.1-7.EL4.2  
ruby-mode-1.8.1-7.EL4.2  
ruby-devel-1.8.1-7.EL4.2  
ruby-libs-1.8.1-7.EL4.2  
irb-1.8.1-7.EL4.2  
So you might get ruby but not irb.

The authors extol the virtues of ri. I found that ri File (or ri  
almost anything) gave:  
No ri documentation found in:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/share/ri/1.8/system  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/share/ri/1.8/site  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/root/.rdoc

These problems can be blamed on incompetent packaging or installation  
of Ruby, but it seems to me that the authors of Ruby tutorials should  
warn their readers about such problems and perhaps give some hints  
about how to resolve them.

In Redhat Enterprise Linux 4, I was able to resolve the irb problem  
simply by installing the irb-1.8.1-7 package.

At to the ri problem,I found no tutorials that mention rdoc or  
configure ri. Reading the output of  
ri -h  
I concluded it would suffice to run  
rdoc --ri  
which creates a director called "doc" in my home directory. And this  
makes ri work for the basic ruby objects. (Of course a more efficient  
way on a mult-user system would be to create this "doc" file in only  
one location and direct the ri for each user to it. It would be nice  
to have a simple example of this. )

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [30 March 2006 17:59 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/2 "2006-03-30T17:59:19Z")

</div>

we use rhe on all our machines and i can tell you this: the rh ruby rpms are  
broken, broken, broken, broken - do not use them and please complain to redhat  
(i have several times).

all the issues you are seeing are resolved by using almost any installation  
method besides rhe rpms. it even works on fedora.

i manage about 50 machines and we've taken the compile route - however, since  
all the boxes see a common nfs mount we install only once there.

rhe rpms are really really bad in general and should be avoided - for example  
the image magic packages break (silently) loseless compression of jp2s... the  
perl rpm has a userland kernel panic causing bug, etc, etc.

we use plain vanilla rhe, installing anything 'important' via compilation and  
have 100% success with this approach. it's also immune to the auto-upgrade of  
enterprise systems breaking 24x7 systems on a late sunday evening.

the reality is that there is exactly one method of installing ruby, or  
anything else for that matter, that will work on any platform:

&nbsp;&nbsp;&nbsp;./configure --prefix=dst && make && sudo make install

this becomes \_\_really\_\_ important once one starts installing gems that  
auto-compile and then upgrade ruby using rpms - only to have all gems start  
giving bus errors... correct compilation avoids this entirely in addition to  
allowing multiple ruby versions to be installed (which we require).

sad. but true.

regards.

-a

> **···**
>
> On Fri, 31 Mar 2006 stephen.tashiro@us.army.mil wrote:
> 
> > Perhaps an inflamatory title - but it answers some simple questions.
> > 
> > Having looked at the Pixaxe book and visited various websites with Ruby  
> > tutorials, I think there is an unintentional hype of certain Ruby  
> > features. We may blame this on the distributors of software. For  
> > example, the authors tell us how easy it is to use irb. On my Redhat  
> > Enterprise Linux machine, ruby puts("Hello World") ran fine. But irb  
> > was not a command known to bash. The redhat distribution has the  
> > packages:  
> > ruby-docs-1.8.1-7.EL4.2  
> > ruby-tcltk-1.8.1-7.EL4.2  
> > ruby-1.8.1-7.EL4.2  
> > ruby-mode-1.8.1-7.EL4.2  
> > ruby-devel-1.8.1-7.EL4.2  
> > ruby-libs-1.8.1-7.EL4.2  
> > irb-1.8.1-7.EL4.2  
> > So you might get ruby but not irb.
> > 
> > The authors extol the virtues of ri. I found that ri File (or ri  
> > almost anything) gave:  
> > No ri documentation found in:  
> > &nbsp;&nbsp;&nbsp;&nbsp;/usr/share/ri/1.8/system  
> > &nbsp;&nbsp;&nbsp;&nbsp;/usr/share/ri/1.8/site  
> > &nbsp;&nbsp;&nbsp;&nbsp;/root/.rdoc
> > 
> > These problems can be blamed on incompetent packaging or installation  
> > of Ruby, but it seems to me that the authors of Ruby tutorials should  
> > warn their readers about such problems and perhaps give some hints  
> > about how to resolve them.
> > 
> > In Redhat Enterprise Linux 4, I was able to resolve the irb problem  
> > simply by installing the irb-1.8.1-7 package.
> > 
> > At to the ri problem,I found no tutorials that mention rdoc or  
> > configure ri. Reading the output of  
> > ri -h  
> > I concluded it would suffice to run  
> > rdoc --ri  
> > which creates a director called "doc" in my home directory. And this  
> > makes ri work for the basic ruby objects. (Of course a more efficient  
> > way on a mult-user system would be to create this "doc" file in only  
> > one location and direct the ri for each user to it. It would be nice  
> > to have a simple example of this. )
> 
> --  
> share your knowledge. it's a way to achieve immortality.  
> - h.h. the 14th dali lama

---

<div class="post-metadata">

**Author:** ![Hans\_Fugal3](https://avatars.discourse-cdn.com/v4/letter/h/34f0e0/32.png) [@Hans\_Fugal3](https://rubytalk.org/u/Hans_Fugal3)\
**Post date:** [30 March 2006 18:28 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/3 "2006-03-30T18:28:43Z")

</div>

I can second that. I have never worked with a more frustrating distribution than R\_HEL\_ (emphasis added).

> **···**
>
> ara.t.howard@noaa.gov wrote:
> 
> > we use rhe on all our machines and i can tell you this: the rh ruby rpms are  
> > broken, broken, broken, broken - do not use them and please complain to redhat  
> > (i have several times).
> > 
> > all the issues you are seeing are resolved by using almost any installation  
> > method besides rhe rpms. it even works on fedora.
> > 
> > i manage about 50 machines and we've taken the compile route - however, since  
> > all the boxes see a common nfs mount we install only once there.
> > 
> > rhe rpms are really really bad in general and should be avoided - for example  
> > the image magic packages break (silently) loseless compression of jp2s... the  
> > perl rpm has a userland kernel panic causing bug, etc, etc.
> > 
> > we use plain vanilla rhe, installing anything 'important' via compilation and  
> > have 100% success with this approach. it's also immune to the auto-upgrade of  
> > enterprise systems breaking 24x7 systems on a late sunday evening.
> > 
> > the reality is that there is exactly one method of installing ruby, or  
> > anything else for that matter, that will work on any platform:
> > 
> > &nbsp;&nbsp;./configure --prefix=dst && make && sudo make install
> > 
> > this becomes \_\_really\_\_ important once one starts installing gems that  
> > auto-compile and then upgrade ruby using rpms - only to have all gems start  
> > giving bus errors... correct compilation avoids this entirely in addition to  
> > allowing multiple ruby versions to be installed (which we require).
> > 
> > sad. but true.

---

<div class="post-metadata">

**Author:** ![Randy\_Kramer](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@Randy\_Kramer](https://rubytalk.org/u/Randy_Kramer)\
**Post date:** [30 March 2006 22:08 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/4 "2006-03-30T22:08:32Z")

</div>

Hmm, interesting idea--tell me more:

&nbsp;&nbsp;&nbsp;\* Is that partition mounted as one of the standard partitions (/usr...) or  
something else?

&nbsp;&nbsp;&nbsp;\* Do you have to do anything on each of those 50 machines, or just mount  
the NFS partition--hmm, I guess you'd at least have to add something to the  
PATH of each user (at least, if a non-standard partition)?

I might try this, or even on a local non-standard partition (I guess I just  
have to set the prefix appropriately).

This might solve some problems for me--I'm trying to get TkHTML working for  
me, and by now I'm concerned that I've tried so many things I've created more  
problems for myself--I could start completely over on a new partition.

Then I guess I'd have to do the ./configure --prefix=dst && make && sudo make  
install process for:

Ruby  
tcltk (or ActiveTcl)  
TkHTML (although in reading the instructions for this I realize there are some  
special things to deal with, like the "parallel" bld directory)

More info:

Part of my problem is that I've compiled Ruby, then installed ActiveTcl, and I  
don't know how to uninstall something that I installed by compiling.  
ActiveTcl seemed to have an uninstall.tcl script, but that failed for me. I  
guess I'll just go around and delete all files and directories that look like  
they have anything to do with Ruby, tcltk, ActiveTcl, or TkHTML, and then  
start over.

This is on a Mandriva2006 system. I don't know whether the rpms on Mandriva  
are to blame in any way--I suspect most of the problem(s) are just my  
ignorance/inexperience in setting something like this up.

Randy Kramer

> **···**
>
> On Thursday 30 March 2006 12:59 pm, ara.t.howard@noaa.gov wrote:
> 
> > i manage about 50 machines and we've taken the compile route - however,  
> > since all the boxes see a common nfs mount we install only once there.

---

<div class="post-metadata">

**Author:** ![Stephen\_Tashiro](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@Stephen\_Tashiro](https://rubytalk.org/u/Stephen_Tashiro)\
**Post date:** [30 March 2006 23:33 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/5 "2006-03-30T23:33:42Z")

</div>

I tried the suggestion of installing from source and I like the result  
better. (My suggestion to run rdoc --ri is only useful if you run it  
in some directory whose tree contains the source code (\*.c) files for  
Ruby. ) After an install from source with  
../configure  
make  
su  
make install

The ri and irb commands work fine. But when I try to use FxRuby, the  
extension for the Fox Gui Toolkit, there are problems. The extension  
wants the library libruby.so, which is missing. I tried

make distclean  
../configure --enable-shared --enable-install-doc --enable-pthread  
(As if I really knew what I was doing !)  
make  
make install-all

Then I had a libruby.so and ruby, irb and ri still worked.

However the elementary test

> require 'fox14'

fails since it cannot find the files fox14/core.rb and fox14/core.so.  
An strace of this process shows it is looking in the correct path for  
the files. (I resorted to running irb in the fox14 directory.) The  
problem is that the files were not produced when I compiled fox-1.4.32.

I'll be delighted if someone can tell me the answer to that problem.  
However to return to generalities: I think people trying to use Ruby  
face more of a challenge than Perl and Python users since they are less  
likely to find Ruby installed and ready-to-go. In the current epoch,  
writers of tutorials would do better to give detailed coverage of  
installation problems. Otherwise the pages about how easy and nice  
Ruby is will seem a fraud.

For example, if you read the typical exposition of the  
require 'xyz'  
"command, it doesn't explain how the name 'xyz' is connected to any  
file on the machine. By experiment it seems to search for a directory  
named 'xyz'. What paths does it take? What files does it need in that  
directory? If everything is perfectly installed you don't have to  
worry about this, but in practice you do.

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [30 March 2006 22:21 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/6 "2006-03-30T22:21:49Z")

</div>

> > i manage about 50 machines and we've taken the compile route - however,  
> > since all the boxes see a common nfs mount we install only once there.
> 
> Hmm, interesting idea--tell me more:
> 
> &nbsp;&nbsp;\* Is that partition mounted as one of the standard partitions (/usr...) or  
> something else?

something else = prefix=/dmsp/reference/

we have tons of stuff living there

> &nbsp;&nbsp;\* Do you have to do anything on each of those 50 machines, or just mount  
> the NFS partition--hmm, I guess you'd at least have to add something to the  
> PATH of each user (at least, if a non-standard partition)?

yes. PATH must be set. this is done in /etc/profile.d/dmsp.sh. we also set  
LD\_LIBRARY\_PATH here - thought this needed be done (see below)

> I might try this, or even on a local non-standard partition (I guess I just  
> have to set the prefix appropriately).
> 
> This might solve some problems for me--I'm trying to get TkHTML working for  
> me, and by now I'm concerned that I've tried so many things I've created more  
> problems for myself--I could start completely over on a new partition.

exactly one of the issues i had! i have tcl/tk compiled and installed this  
way too.

> Then I guess I'd have to do the ./configure --prefix=dst && make && sudo make  
> install process for:
> 
> Ruby  
> tcltk (or ActiveTcl)  
> TkHTML (although in reading the instructions for this I realize there are some  
> special things to deal with, like the "parallel" bld directory)

yup.

> More info:
> 
> Part of my problem is that I've compiled Ruby, then installed ActiveTcl, and I  
> don't know how to uninstall something that I installed by compiling.  
> ActiveTcl seemed to have an uninstall.tcl script, but that failed for me. I  
> guess I'll just go around and delete all files and directories that look like  
> they have anything to do with Ruby, tcltk, ActiveTcl, or TkHTML, and then  
> start over.
> 
> This is on a Mandriva2006 system. I don't know whether the rpms on Mandriva  
> are to blame in any way--I suspect most of the problem(s) are just my  
> ignorance/inexperience in setting something like this up.

if you follow these steps just about anything will work:

&nbsp;&nbsp;&nbsp;- chose a common nfs location. we'll call it /nfs

&nbsp;&nbsp;&nbsp;- every single time you compile something do this

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export LD\_RUN\_PATH=/nfs/lib  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export LD\_LIBRARY\_PATH=/nfs/lib  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;./configure --prefix=/nfs && make && make install

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i set LD\_LIBRARY\_PATH and LD\_RUN\_PATH in my .bashrc because i do this so  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;much. the cool thing with LD\_RUN\_PATH is that it \_\_encodes\_\_  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inter-library dependancies (so ruby tk.so needs libtk.so needs ...) such  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that users do not need to set LD\_LIBRARY\_PATH themselves. of course they  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;may, but they do not have to

&nbsp;&nbsp;&nbsp;- all users of code on this partiion need only do

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export PATH=/nfs/bin:$PATH

i have a /nfs/build and /nfs/packages - you can guess what these are for 😉  
if you like this approach you may want to check out gnu stowe. i find it easy  
enough to do by hand though...

regards.

-a

> **···**
>
> On Fri, 31 Mar 2006, Randy Kramer wrote:
> 
> > On Thursday 30 March 2006 12:59 pm, ara.t.howard@noaa.gov wrote:
> 
> --  
> share your knowledge. it's a way to achieve immortality.  
> - h.h. the 14th dali lama

---

<div class="post-metadata">

**Author:** ![Ryan\_Allen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@Ryan\_Allen](https://rubytalk.org/u/Ryan_Allen)\
**Post date:** [30 March 2006 23:58 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/7 "2006-03-30T23:58:16Z")

</div>

Hi Guys (and Gals!)

This is my first post on the list, so Hello!

Something very strange is happening (as far as I can tell) with a float comparison; here is the code in question:

("55.59".to\_f / 100) == 0.5559 # returns false

However:

"55.59".to\_f / 100 # returns Float 0.5559  
0.5559 # returns Float 0.5559  
0.5559 == 0.5559 # returns true

And more!:

("55.5".to\_f / 100) == 0.555 # returns true  
("55.53".to\_f / 100) == 0.5553 # returns true  
("55.56".to\_f / 100) == 0.5556 # returns true  
("55.58".to\_f / 100) == 0.5558 # returns true  
("55.59".to\_f / 100) == 0.5559 # returns false !!  
("44.59".to\_f / 100) == 0.4449 # returns true !!  
("44.59".to\_f / 100) == 0.4449 # returns false !!!!

It doesn't seem to like .59's... What did .59 ever do?

I picked this up while writing a unit test, I've run this code in irb and I'm not sure what's going on...

Can anyone shed some light on this?

I'm using ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0]

Cheers,  
Ryan.

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [31 March 2006 00:12 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/8 "2006-03-31T00:12:47Z")

</div>

> I tried the suggestion of installing from source and I like the result  
> better. (My suggestion to run rdoc --ri is only useful if you run it  
> in some directory whose tree contains the source code (\*.c) files for  
> Ruby. ) After an install from source with  
> ../configure  
> make  
> su  
> make install

great.

> The ri and irb commands work fine. But when I try to use FxRuby, the  
> extension for the Fox Gui Toolkit, there are problems. The extension  
> wants the library libruby.so, which is missing. I tried
> 
> make distclean  
> ../configure --enable-shared --enable-install-doc --enable-pthread  
> (As if I really knew what I was doing !)  
> make  
> make install-all
> 
> Then I had a libruby.so and ruby, irb and ri still worked.
> 
> However the elementary test  
> \> require 'fox14'  
> fails since it cannot find the files fox14/core.rb and fox14/core.so.  
> An strace of this process shows it is looking in the correct path for  
> the files. (I resorted to running irb in the fox14 directory.) The  
> problem is that the files were not produced when I compiled fox-1.4.32.

here is what i think happened (largely guessing):

&nbsp;&nbsp;&nbsp;- you compiled ruby using defaults. this installed into --prefix=/usr/local

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;see if this is true. if so see what happens why you type

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/local/bin/irb

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;does it work? if so great. note that you still probably have another  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ruby and irb in /usr/bin!

&nbsp;&nbsp;&nbsp;- now, rhe is evil and does not look in /usr/local/lib for linking. the way  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to handle this is to configure the linker properly. do a 'man ldconfig'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or 'man ld.so' - basically you have to add a line with '/usr/local/lib' to  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'/etc/ld.so.conf' and run 'ldconfig'. this just tells the system to look  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;here for libs. the reason you want to do this is because your libruby.so  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is probably in /usr/local/lib/libruby.so now. (is it?)

&nbsp;&nbsp;&nbsp;- here is a totally general way to compile stuff, including stuff that has  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mutual dependancies

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export prefix=/usr/local/

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export LD\_LIBRARY\_PATH=$prefix/lib

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export LD\_RUN\_PATH=$prefix/lib

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export PATH=$prefix/lib

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;./configure --prefix=$prefix && make && sudo make install

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(note: never, never, never compile as root)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if you build ruby this was and then fox all should be well. ping me  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;offline if you stil have issues. you can probably recover what you have  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by setting the right ENV vars - but it may be easier to start over with  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ruby first... maybe not.

if you have issues ping me offline so we don't bore everyone...

> I'll be delighted if someone can tell me the answer to that problem.  
> However to return to generalities: I think people trying to use Ruby  
> face more of a challenge than Perl and Python users since they are less  
> likely to find Ruby installed and ready-to-go. In the current epoch,  
> writers of tutorials would do better to give detailed coverage of  
> installation problems. Otherwise the pages about how easy and nice  
> Ruby is will seem a fraud.
> 
> For example, if you read the typical exposition of the  
> require 'xyz'  
> "command, it doesn't explain how the name 'xyz' is connected to any  
> file on the machine. By experiment it seems to search for a directory  
> named 'xyz'. What paths does it take? What files does it need in that  
> directory? If everything is perfectly installed you don't have to  
> worry about this, but in practice you do.

true statements all.

like i said before though - the best (but painful) - answer (imho) is to learn  
about the compilers and linkers on your system. as lame as this sounds one  
can take solace in the fact that it's like learning 'vi' - once you know it  
you're set on \_\_any\_\_ \*nix system - including macs.

btw. are you a sysad? we sure can't get root on ANY of our systems now  
unless one is a sysad...

kind regards.

-a

> **···**
>
> On Fri, 31 Mar 2006 stephen.tashiro@us.army.mil wrote:  
> --  
> share your knowledge. it's a way to achieve immortality.  
> - h.h. the 14th dali lama

---

<div class="post-metadata">

**Author:** ![Mike\_Stok1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/mike_stok1/32/2065_2.png) [@Mike\_Stok1](https://rubytalk.org/u/Mike_Stok1)\
**Post date:** [31 March 2006 00:04 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/9 "2006-03-31T00:04:55Z")

</div>

You might want to look at [http://docs.sun.com/source/806-3568/ncg\_goldberg.html](http://docs.sun.com/source/806-3568/ncg_goldberg.html) and [http://support.microsoft.com/kb/q69333/](http://support.microsoft.com/kb/q69333/)

ratdog:~ mike$ irb  
irb(main):001:0\> '%.40f' % 0.5559  
=\> "0.5558999999999999497291014449729118496180"  
irb(main):002:0\> '%.40f' % (55.59 / 100)  
=\> "0.5559000000000000607514039074885658919811"  
irb(main):003:0\> '%.40f' % ("55.59".to\_f / 100)  
=\> "0.5559000000000000607514039074885658919811"

Mike

> **···**
>
> On 30-Mar-06, at 6:58 PM, Ryan Allen wrote:
> 
> > Hi Guys (and Gals!)
> > 
> > This is my first post on the list, so Hello!
> > 
> > Something very strange is happening (as far as I can tell) with a float comparison; here is the code in question:
> > 
> > ("55.59".to\_f / 100) == 0.5559 # returns false
> > 
> > However:
> > 
> > "55.59".to\_f / 100 # returns Float 0.5559  
> > 0.5559 # returns Float 0.5559  
> > 0.5559 == 0.5559 # returns true
> > 
> > And more!:
> > 
> > ("55.5".to\_f / 100) == 0.555 # returns true  
> > ("55.53".to\_f / 100) == 0.5553 # returns true  
> > ("55.56".to\_f / 100) == 0.5556 # returns true  
> > ("55.58".to\_f / 100) == 0.5558 # returns true  
> > ("55.59".to\_f / 100) == 0.5559 # returns false !!  
> > ("44.59".to\_f / 100) == 0.4449 # returns true !!  
> > ("44.59".to\_f / 100) == 0.4449 # returns false !!!!
> > 
> > It doesn't seem to like .59's... What did .59 ever do?
> > 
> > I picked this up while writing a unit test, I've run this code in irb and I'm not sure what's going on...
> > 
> > Can anyone shed some light on this?
> > 
> > I'm using ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0]
> > 
> > Cheers,  
> > Ryan.
> 
> --
> 
> Mike Stok \<mike@stok.ca\>  
> [http://www.stok.ca/~mike/](http://www.stok.ca/~mike/)
> 
> The "`Stok' disclaimers" apply.

---

<div class="post-metadata">

**Author:** ![Matthew\_D\_Moss](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@Matthew\_D\_Moss](https://rubytalk.org/u/Matthew_D_Moss)\
**Post date:** [31 March 2006 00:07 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/10 "2006-03-31T00:07:01Z")

</div>

> ("44.59".to\_f / 100) == 0.4449 # returns true !!  
> ("44.59".to\_f / 100) == 0.4449 # returns false !!!!

Typos? You typed the same exact line twice and it comes back with two  
different answers?

In any case, exact equality comparisons of floating-point numbers is  
bad. Don't do it.

Either compare with a small threshold, or deal with rationals.

---

<div class="post-metadata">

**Author:** ![Tim\_Hunter](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@Tim\_Hunter](https://rubytalk.org/u/Tim_Hunter)\
**Post date:** [31 March 2006 00:13 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/11 "2006-03-31T00:13:43Z")

</div>

Ryan Allen wrote:

> Hi Guys (and Gals!)
> 
> This is my first post on the list, so Hello!
> 
> Something very strange is happening (as far as I can tell) with a float comparison; here is the code in question:
> 
> ("55.59".to\_f / 100) == 0.5559 # returns false
> 
> However:
> 
> "55.59".to\_f / 100 # returns Float 0.5559  
> 0.5559 # returns Float 0.5559  
> 0.5559 == 0.5559 # returns true
> 
> And more!:
> 
> ("55.5".to\_f / 100) == 0.555 # returns true  
> ("55.53".to\_f / 100) == 0.5553 # returns true  
> ("55.56".to\_f / 100) == 0.5556 # returns true  
> ("55.58".to\_f / 100) == 0.5558 # returns true  
> ("55.59".to\_f / 100) == 0.5559 # returns false !!  
> ("44.59".to\_f / 100) == 0.4449 # returns true !!  
> ("44.59".to\_f / 100) == 0.4449 # returns false !!!!
> 
> It doesn't seem to like .59's... What did .59 ever do?
> 
> I picked this up while writing a unit test, I've run this code in irb and I'm not sure what's going on...
> 
> Can anyone shed some light on this?
> 
> I'm using ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0]
> 
> Cheers,  
> Ryan.

The comparison of floating-point numbers is notoriously problematic throughout all computing, not just Ruby. Here's a good description of the problem: [http://en.wikipedia.org/wiki/Floating\_point\](http://en.wikipedia.org/wiki/Floating_point%5C). You can also find many discussions of this same "problem" by searching the archives of this list.

Typically you don't test two floating-point numbers for equality, you test that the difference is very small. This is what the assert\_in\_delta assertion is for.

---

<div class="post-metadata">

**Author:** ![Thomas\_E\_Enebo](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@Thomas\_E\_Enebo](https://rubytalk.org/u/Thomas_E_Enebo)\
**Post date:** [31 March 2006 00:13 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/12 "2006-03-31T00:13:52Z")

</div>

On Fri, 31 Mar 2006, Ryan Allen defenestrated me:

> Hi Guys (and Gals!)
> 
> This is my first post on the list, so Hello!
> 
> Something very strange is happening (as far as I can tell) with a  
> float comparison; here is the code in question:
> 
> ("55.59".to\_f / 100) == 0.5559 # returns false
> 
> It doesn't seem to like .59's... What did .59 ever do?
> 
> I picked this up while writing a unit test, I've run this code in irb  
> and I'm not sure what's going on...
> 
> Can anyone shed some light on this?

&nbsp;&nbsp;Looking at some IEEE spec will explain this in agonizing detail, but  
simply stated numbers in a computer are stored in a base 2 format. The  
math you are doing is base 10. Not all base 10 values can be perfectly  
represented in base 2. This can cause calculations to not quite come  
out right.

&nbsp;&nbsp;A book on numerical analysis can also be a good intro on this stuff.

-Tom

> **···**
>
> --  
> + [http://www.tc.umn.edu/~enebo](http://www.tc.umn.edu/~enebo) +---- [mailto:enebo@acm](mailto:enebo@acm).org ----+
> 
> > Thomas E Enebo, Protagonist | "Luck favors the prepared |  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\> mind." -Louis Pasteur |

---

<div class="post-metadata">

**Author:** ![List\_Recv](https://avatars.discourse-cdn.com/v4/letter/l/dec6dc/32.png) [@List\_Recv](https://rubytalk.org/u/List_Recv)\
**Post date:** [31 March 2006 04:03 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/13 "2006-03-31T04:03:44Z")

</div>

Just to corroborate: I actually do prefer RHEL distros, but the Ruby  
RPM's should be avoided.

---

<div class="post-metadata">

**Author:** ![Randy\_Kramer](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@Randy\_Kramer](https://rubytalk.org/u/Randy_Kramer)\
**Post date:** [31 March 2006 15:47 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/14 "2006-03-31T15:47:58Z")

</div>

Thanks very much! I haven't tried this yet, but it looks like it should solve  
a lot of my problems.

Randy Kramer

> **···**
>
> On Thursday 30 March 2006 05:21 pm, ara.t.howard@noaa.gov wrote:
> 
> > On Fri, 31 Mar 2006, Randy Kramer wrote:  
> > \> On Thursday 30 March 2006 12:59 pm, ara.t.howard@noaa.gov wrote:  
> > if you follow these steps just about anything will work:
> > 
> > &nbsp;&nbsp;&nbsp;- chose a common nfs location. we'll call it /nfs
> > 
> > &nbsp;&nbsp;&nbsp;- every single time you compile something do this
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export LD\_RUN\_PATH=/nfs/lib  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export LD\_LIBRARY\_PATH=/nfs/lib  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;./configure --prefix=/nfs && make && make install
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i set LD\_LIBRARY\_PATH and LD\_RUN\_PATH in my .bashrc because i do this  
> > so much. the cool thing with LD\_RUN\_PATH is that it \_\_encodes\_\_  
> > inter-library dependancies (so ruby tk.so needs libtk.so needs ...) such  
> > that users do not need to set LD\_LIBRARY\_PATH themselves. of course they  
> > may, but they do not have to
> > 
> > &nbsp;&nbsp;&nbsp;- all users of code on this partiion need only do
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export PATH=/nfs/bin:$PATH
> > 
> > i have a /nfs/build and /nfs/packages - you can guess what these are for  
> > 😉 if you like this approach you may want to check out gnu stowe. i find  
> > it easy enough to do by hand though...

---

<div class="post-metadata">

**Author:** ![Ryan\_Allen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@Ryan\_Allen](https://rubytalk.org/u/Ryan_Allen)\
**Post date:** [31 March 2006 00:29 UTC](https://rubytalk.org/t/unintentional-hype-of-ruby-irb-and-ri/26253/15 "2006-03-31T00:29:05Z")

</div>

Thank you for the replies!

I should have searched the list first before asking!

Ryan.
