# Re: greatest float smaller than 1.0?

**URL:** <https://www.ruby-forum.com/t/re-greatest-float-smaller-than-1-0/94966>\
**Category:** Ruby\
**Created:** [May 18, 2006, 11:03am UTC](https://www.ruby-forum.com/t/re-greatest-float-smaller-than-1-0/94966 "2006-05-18T11:03:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 18, 2006, 11:03am UTC](https://www.ruby-forum.com/t/re-greatest-float-smaller-than-1-0/94966/1 "2006-05-18T11:03:17Z")

</div>

> To anyone out there who is engaged in coding these sorts of things a lot,  
> I would strongly recommend that they at the very least try reading a  
> book like Forman S. Acton’s “Numerical Methods that Work” and/or W.H.  
> Press (et. al.) “Numerical Recipes” before they proceed. I’ve had  
> these kinds of things bite me in the past, developing answers that  
> were totally wrong, even though the formulae in use were apparently  
> correct. And they would have been, had my floating point numbers been  
> arbitrary precision numbers instead! It’s issues such as this that  
> usually make it better and safer to use well-tested numerics libraries  
> where they exist rather than rolling your own.

I fully agree with you. I’d like to add that there is, among others,  
gsl and its ruby bindings rb-gsl that can do this job for you.

Since Ruby is object-oriented, using fractions instead of floats  
can be an option, also (but if you use numerical libraries, it’s mostly  
because you want to crunch a huge amount of numbers fast,  
and don’t care too much about exact results ;-).

Even more sophisticated things can be done, using some more  
advanced algebra, if you want to represent things like the  
square root of two correctly. (No float or fraction can do that,  
and the first ancient Greek who noticed this was reportedly killed  
for noticing this and thus rebelling against the dogma of the  
Pythagorean faith he adhered to. It is said that as a consequence,  
the Pythagorean community split up into “hearers” and “mathematicians”  
as a result of this incident.)

You can represent 2.sqrt it as a root of the Polynomial x**2-2, i.e., a  
solution of x**2-2=0.  
Polynomials are implemented in Ruby here:

\_[http://www.math.kobe-u.ac.jp/~kodama/tips-RubyPoly.html\_](http://www.math.kobe-u.ac.jp/~kodama/tips-RubyPoly.html_)  
([Polynomial class for Ruby](http://www.math.kobe-u.ac.jp/~kodama/tips-RubyPoly.html))

Best regards,

Axel
