Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Rounding a floating point number declared in "double"

Reply
Thread Tools

Rounding a floating point number declared in "double"

 
 
Sooha Park Lee
Guest
Posts: n/a
 
      07-16-2003
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

 
Reply With Quote
 
 
 
 
Artie Gold
Guest
Posts: n/a
 
      07-16-2003
Sooha Park Lee wrote:
> 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


--
Artie Gold -- Austin, Texas

 
Reply With Quote
 
 
 
 
Mark McIntyre
Guest
Posts: n/a
 
      07-16-2003
On Wed, 16 Jul 2003 18:26:19 +0000 (UTC), in comp.lang.c ,
http://www.velocityreviews.com/forums/(E-Mail Removed) (Sooha Park Lee) wrote:

>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.



--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rounding a floating point number jacob navia C Programming 21 02-28-2008 01:47 AM
Floating point subtraction rounding error (NOT display error) Keflavich Python 13 12-14-2007 03:56 PM
Floating point rounding error Mukesh_Singh_Nick@yahoo.com C Programming 15 07-02-2007 08:11 AM
floating point rounding hg Python 4 03-10-2007 09:33 AM
Rounding a floating point number declared in "double" Sooha Park Lee C Programming 2 07-17-2003 07:09 PM



Advertisments