how can i verify if a number has mantissa???

Discussion in 'C Programming' started by fzmaster, Nov 25, 2005.

  1. fzmaster

    fzmaster Guest

    Actually i need to know how to detect if a number is a perfect square.
    But i'v been thinking..
    if i sqrt(x) and check if this result has mantissa... so it is not a
    interger...and surely not a perfect square.

    Well my question is... how can i verify if a number has mantissa???

    i'm thx full for R help.
    bye.
    fzmaster
    UNIVERSIDADE FEDERAL DO ESPIRITO SANTO - UFES
    BRASIL
    fzmaster, Nov 25, 2005
    #1
    1. Advertising

  2. >Actually i need to know how to detect if a number is a perfect square.
    >But i'v been thinking..
    >if i sqrt(x) and check if this result has mantissa... so it is not a
    >interger...and surely not a perfect square.
    >
    >Well my question is... how can i verify if a number has mantissa???


    A floating point number *ALWAYS* has a mantissa, regardless of whether
    it is an exact integer or not.

    fmod(x, 1.0) should return an exact zero if x is an exact integer
    (in a floating-point variable). Two problems: fmod() is not defined
    to be exact, although in practice that should not be a problem.
    Also x might not be an exact integer even if it mathematically
    SHOULD be exact, and sqrt() is likely to have roundoff error.

    Gordon L. Burditt
    Gordon Burditt, Nov 25, 2005
    #2
    1. Advertising

  3. fzmaster

    Saif Guest

    fzmaster wrote:
    > Actually i need to know how to detect if a number is a perfect square.
    > But i'v been thinking..
    > if i sqrt(x) and check if this result has mantissa... so it is not a
    > interger...and surely not a perfect square.
    >
    > Well my question is... how can i verify if a number has mantissa???


    If(number - floor(number) == 0) then your number is an integer
    else not.
    Saif, Nov 25, 2005
    #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. sankar
    Replies:
    5
    Views:
    2,932
    Jerry Avins
    Nov 24, 2005
  2. Carramba

    comparing mantissa

    Carramba, Jul 12, 2007, in forum: C Programming
    Replies:
    20
    Views:
    840
    user923005
    Jul 16, 2007
  3. Peng Yu

    How to get mantissa?

    Peng Yu, Jul 15, 2008, in forum: C++
    Replies:
    2
    Views:
    964
    James Kanze
    Jul 15, 2008
  4. RolfK
    Replies:
    1
    Views:
    1,752
    Mukul Gandhi
    Jan 20, 2009
  5. Steven D'Aprano

    mantissa and exponent in base 10

    Steven D'Aprano, Oct 6, 2010, in forum: Python
    Replies:
    3
    Views:
    3,636
    Dave Angel
    Oct 7, 2010
Loading...

Share This Page