Rounding a floating point number declared in "double"

S

Sooha Park Lee

I would like to compare two "double" numbers.
To overcome round-off error, I am using the following strategy:
rounding each number and try to convert it into interger by multiplying 10E6.
One example of number is 0.765543.

I do not want "ceil" or "floor".

Any idea will be welcome.

Can I find any smart code already existed on the web?

Thank you.

-Sooha
 
A

Artie Gold

Sooha said:
I would like to compare two "double" numbers.
To overcome round-off error, I am using the following strategy:
rounding each number and try to convert it into interger by multiplying 10E6.
One example of number is 0.765543.

I do not want "ceil" or "floor".
Bad Idea.

You've read the FAQ, of course (as I assume you're a reasonable user of
usenet). You must have missed the following:

http://www.eskimo.com/~scs/C-faq/s14.html

HTH,
--ag
 
M

Mark McIntyre

On Wed, 16 Jul 2003 18:26:19 +0000 (UTC), in comp.lang.c ,
I would like to compare two "double" numbers.
To overcome round-off error, I am using the following strategy:
rounding each number and try to convert it into interger by multiplying 10E6.

the "standard" way is to use fabs(a-b) and compare that to some small
constant eg 1e-6 or whatever tolerance you want.
 

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

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top