[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Using assert_in_delta for floats with extended notation

Daniel Berger

6/10/2007 6:53:00 PM

Hi all,

For comparing floats I normally do something like this:

assert_in_delta('100.324', '100.32', 0.01)

However, for extended notation it breaks down:

assert_in_delta(1.34341429278853e+15,
18446744073709551616.quo(13731.24), 1.0)

That gives me a failure. What's the proper way to test this?

Thanks,

Dan

2 Answers

Jano Svitok

6/11/2007 11:32:00 PM

0

On 6/10/07, Daniel Berger <djberg96@gmail.com> wrote:
> Hi all,
>
> For comparing floats I normally do something like this:
>
> assert_in_delta('100.324', '100.32', 0.01)
>
> However, for extended notation it breaks down:
>
> assert_in_delta(1.34341429278853e+15,
> 18446744073709551616.quo(13731.24), 1.0)
>
> That gives me a failure. What's the proper way to test this?
>
> Thanks,
>
> Dan

assert_in_delta(1.34341429278853e+15, 18446744073709551616.quo(13731.24), 2.0)

works. (the difference is 1.75)

Jano

Daniel Berger

6/12/2007 12:43:00 AM

0



On Jun 11, 5:32 pm, "Jano Svitok" <jan.svi...@gmail.com> wrote:
> On 6/10/07, Daniel Berger <djber...@gmail.com> wrote:
>
>
>
> > Hi all,
>
> > For comparing floats I normally do something like this:
>
> > assert_in_delta('100.324', '100.32', 0.01)
>
> > However, for extended notation it breaks down:
>
> > assert_in_delta(1.34341429278853e+15,
> > 18446744073709551616.quo(13731.24), 1.0)
>
> > That gives me a failure. What's the proper way to test this?
>
> > Thanks,
>
> > Dan
>
> assert_in_delta(1.34341429278853e+15, 18446744073709551616.quo(13731.24), 2.0)
>
> works. (the difference is 1.75)
>
> Jano

Thanks. I suck.

Dan