Rounding a floating point number declared in "double"

Discussion in 'C Programming' started by Sooha Park Lee, Jul 16, 2003.

  1. 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
    Sooha Park Lee, Jul 16, 2003
    #1
    1. Advertising

  2. Sooha Park Lee

    Artie Gold Guest

    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
    Artie Gold, Jul 16, 2003
    #2
    1. Advertising

  3. On Wed, 16 Jul 2003 18:26:19 +0000 (UTC), in comp.lang.c ,
    (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 =---
    Mark McIntyre, Jul 16, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sooha Park Lee

    Rounding a floating point number declared in "double"

    Sooha Park Lee, Jul 16, 2003, in forum: C Programming
    Replies:
    2
    Views:
    314
    martinh
    Jul 17, 2003
  2. hg

    floating point rounding

    hg, Mar 9, 2007, in forum: Python
    Replies:
    4
    Views:
    314
  3. Floating point rounding error

    , Jun 16, 2007, in forum: C Programming
    Replies:
    15
    Views:
    1,890
    Jean-Marc Bourguet
    Jul 2, 2007
  4. jacob navia

    Rounding a floating point number

    jacob navia, Feb 25, 2008, in forum: C Programming
    Replies:
    21
    Views:
    825
    Bartc
    Feb 28, 2008
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,287
    Saraswati lakki
    Jan 6, 2012
Loading...

Share This Page