CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2007
    Posts
    13

    numeric_limits question

    I was wondering what the equivalent to
    Code:
    numeric_limits<double>::infinity()
    numeric_limits<double>::quiet_NaN()
    numeric_limits<double>::signaling_NaN()
    would be in C.

    I have tried
    Code:
    #include <float.h>
    isinf (DBL_MAX + 1)
    and many other variants with no success.

    I would also rather use a macro or a function rather than doing something
    like

    Code:
    isinf (exp (100000))
    Regards,

    crei

  2. #2
    Join Date
    Feb 2005
    Location
    Madrid (Spain)
    Posts
    511

    Re: numeric_limits question

    Try to add the include <math.h>

    From MSDN:
    Code:
    DBL_MAX 1.7976931348623158e+308 Maximum value

  3. #3
    Join Date
    May 2007
    Posts
    13

    Re: numeric_limits question

    But this could vary from compiler to compiler. I need a function or macro. Also what about Nan?

  4. #4
    Join Date
    May 2007
    Posts
    13

    Re: numeric_limits question

    Just to answer my own question just incase anyone else faces this problem:

    In gcc there are INFINITY and NAN defines in math.h. However you need to compile the source with gcc -std::c99. Windows has there own macros. You can find them in float.h

  5. #5
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: numeric_limits question

    The double type follows the IEEE 754 standard, please look it up at wikipedia. Certain bit combinations don´t represent a valid double, instead they´re used to code special cases like NaN, positive infinity and the like. When your compiler does not support these cases you can define them by your own by providing the according bit combinations.
    - Guido

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured