# Float precision and FIT

**URL:** <https://www.ruby-forum.com/t/float-precision-and-fit/49017>\
**Category:** Ruby\
**Created:** [November 28, 2005, 7:08pm UTC](https://www.ruby-forum.com/t/float-precision-and-fit/49017 "2005-11-28T19:08:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ed.howland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ad7895/32.png) [@ed.howland](https://www.ruby-forum.com/u/ed.howland)\
**Post date:** [November 28, 2005, 7:08pm UTC](https://www.ruby-forum.com/t/float-precision-and-fit/49017/1 "2005-11-28T19:08:12Z")

</div>

Hello,

I am trying to get the Division example on the FIT wiki  
[http://fit.c2.com/wiki.cgi?WhatAndHowTalk](http://fit.c2.com/wiki.cgi?WhatAndHowTalk)

to run under Ruby and the Fit framework. I have 2 questions. First I  
get red results on last 3 tests because the precision in the HTML  
table is only up to 8 digits, but Ruby is calculating 15 digits.

And second, even after I adjust the HTML to match the results, they  
till don’t equal. I am thinking this is because of ‘==’ vs. eql? on  
floats.

Is there a way coerce a Ruby float to an aribitray precision via  
truncate or round?

Thanks

---

<div class="post-metadata">

**Author:** ![ed.howland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ad7895/32.png) [@ed.howland](https://www.ruby-forum.com/u/ed.howland)\
**Post date:** [November 28, 2005, 7:20pm UTC](https://www.ruby-forum.com/t/float-precision-and-fit/49017/2 "2005-11-28T19:20:18Z")

</div>

Do you have a FIT fixture for running Ruby ?

j

On 11/28/05, Ed Howland [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> And second, even after I adjust the HTML to match the results, they  
> till don’t equal. I am thinking this is because of ‘==’ vs. eql? on  
> floats.
> 
> Is there a way coerce a Ruby float to an aribitray precision via  
> truncate or round?
> 
> Thanks

–  
“Remember. Understand. Believe. Yield! → [http://ruby-lang.org](http://ruby-lang.org)”

Jeff W.

---

<div class="post-metadata">

**Author:** ![ed.howland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ad7895/32.png) [@ed.howland](https://www.ruby-forum.com/u/ed.howland)\
**Post date:** [November 28, 2005, 7:32pm UTC](https://www.ruby-forum.com/t/float-precision-and-fit/49017/3 "2005-11-28T19:32:27Z")

</div>

On 11/28/05, Jeff W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Do you have a FIT fixture for running Ruby ?
> 
> j

Well, I have the Fit framwork d/l from the aforementioned Wiki. There  
is apparently another  
project in CVS on Rubyforge. Haven’t checked it out yet.

> Jeff W.

Ed

---

<div class="post-metadata">

**Author:** ![ed.howland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ad7895/32.png) [@ed.howland](https://www.ruby-forum.com/u/ed.howland)\
**Post date:** [November 28, 2005, 7:48pm UTC](https://www.ruby-forum.com/t/float-precision-and-fit/49017/4 "2005-11-28T19:48:37Z")

</div>

Ah.

If I remember correctly, there once was rumor that Dave T. was  
working  
on a FIT-like framework for Ruby …

I wonder whatever happened to that project…

I’ve written a little ruby replacement of FIT … I’ll probably post it  
if  
we don’t find that someone else has already done the work.

Haven’t taken the next step and built it into a wiki like the FITnesse  
project …

j.

On 11/28/05, Ed Howland [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Jeff W.
> 
> Ed

–  
“Remember. Understand. Believe. Yield! → [http://ruby-lang.org](http://ruby-lang.org)”

Jeff W.

---

<div class="post-metadata">

**Author:** ![ed.howland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ad7895/32.png) [@ed.howland](https://www.ruby-forum.com/u/ed.howland)\
**Post date:** [November 28, 2005, 8:04pm UTC](https://www.ruby-forum.com/t/float-precision-and-fit/49017/5 "2005-11-28T20:04:45Z")

</div>

On 11/28/05, Jeff W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ah.
> 
> If I remember correctly, there once was rumor that Dave T. was working  
> on a FIT-like framework for Ruby …
> 
> I wonder whatever happened to that project…

I think that is the one I d/l from the wiki. Not sure though.

> I’ve written a little ruby replacement of FIT … I’ll probably post it if  
> we don’t find that someone else has already done the work.
> 
> Haven’t taken the next step and built it into a wiki like the FITnesse  
> project …

There is a version of RubyFIT in CVS on RubyForge. I tried it out and  
it ran the Simple example (eg.Division) right out of the box. Solves  
the precision problem by using a type adapter. Looking forward to how  
that code addresses the 5 digit precision issue in Java v. Ruby.

So take a look at that one. If yours is better/different somehow, go  
ahead and post it.

[http://rubyforge.org/projects/fit](http://rubyforge.org/projects/fit)

> j.

Ed

---

<div class="post-metadata">

**Author:** ![ed.howland](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ad7895/32.png) [@ed.howland](https://www.ruby-forum.com/u/ed.howland)\
**Post date:** [November 28, 2005, 8:12pm UTC](https://www.ruby-forum.com/t/float-precision-and-fit/49017/6 "2005-11-28T20:12:55Z")

</div>

On Nov 28, 2005, at 10:07 AM, Ed Howland wrote:

> And second, even after I adjust the HTML to match the results, they  
> till don’t equal. I am thinking this is because of ‘==’ vs. eql? on  
> floats.

No. Float precision.

> Is there a way coerce a Ruby float to an aribitray precision via  
> truncate or round?

For testing float equality do what Test::Unit’s assert\_in\_delta does.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://segment7.net](http://segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
