Thread: Question about the INFINITY value

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733

    Question about the INFINITY value

    Assuming I add the relative suffix (like INFINITY##f) would decrementing it give the max value of the type? Reason being is I'm trying to extract that value out of GCC builtins:

    Code:
    #ifdef __HAVE_FLOAT16
    typedef _Float16 paw16fd;
    #ifdef INFINITY
    #define PAW16FD_INF (__builtin_huge_inf16())
    #else
    #define PAW16FD_MAX (__builtin_huge_val16())
    #endif
    #endif
    Related question, I extracted that __HAVE_FLOAT16 from the math.h library, is that actually a defined GCC gives or is that just something defined in one it's included headers? Haven't been able to find it yet nor any information on it.

  2. #2
    Registered User
    Join Date
    Feb 2023
    Posts
    12
    Hello.

    Quote Originally Posted by awsdert View Post
    Assuming I add the relative suffix (like INFINITY##f) would decrementing it give the max value of the type? Reason being is I'm trying to extract that value out of GCC builtins:
    Maybe I do not fully understand your goal here, but why not make use of the XXXXXX_MAX family of macros in stddef.h, or if you need floats, HUGE_VAL from math.h? HUGE_VAL is ANSI C, so you definitely have it.

    Related question, I extracted that __HAVE_FLOAT16 from the math.h library, is that actually a defined GCC gives or is that just something defined in one it's included headers? Haven't been able to find it yet nor any information on it.
    If by "is that actually a defined GCC gives" you mean a predefined macro given by the compiler, it doesn't appear to be. By the looks of it, it is defined in the floatn-common.h header from glibc, which can be found here. The header is included by floatn.h (found here, granted, this is an old repository), which finally is included by math.h on systems with glibc (albeit, other libcs might provide the macro).

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by interglobber View Post
    Hello.
    Maybe I do not fully understand your goal here, but why not make use of the XXXXXX_MAX family of macros in stddef.h, or if you need floats, HUGE_VAL from math.h? HUGE_VAL is ANSI C, so you definitely have it.
    Because the defines are not given for float16 etc as far as I've found thus far so the only way to get them is to calculate them somehow, I would rather not resort to using pointer hackery & integer decrement to achieve the same if simply decrementing INFINITY in the correct format would result in what I want anyways

    Quote Originally Posted by interglobber View Post
    If by "is that actually a defined GCC gives" you mean a predefined macro given by the compiler, it doesn't appear to be. By the looks of it, it is defined in the floatn-common.h header from glibc, which can be found here. The header is included by floatn.h (found here, granted, this is an old repository), which finally is included by math.h on systems with glibc (albeit, other libcs might provide the macro).
    Thanks, I found some other macros I'll have to use then, they're just not as flexible due to their FMA specific nature:
    Code:
    __FP_FAST_FMAF16
    __FP_FAST_FMAF32
    __FP_FAST_FMAF64
    __FP_FAST_FMAF128
    __FP_FAST_FMAF32X
    __FP_FAST_FMAF64X
    __FP_FAST_FMAF128X
    Mentioned here: Common Predefined Macros (The C Preprocessor)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i am getting infinity in my program !!! ??
    By rafacnsoccer in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2010, 04:43 PM
  2. Help infinity
    By beginner1 in forum C Programming
    Replies: 2
    Last Post: 05-20-2009, 07:19 AM
  3. Integer infinity?
    By housguest in forum C Programming
    Replies: 1
    Last Post: 04-21-2008, 01:03 AM
  4. tan(pi/2) = infinity; now try to do this is C
    By MatthewDoucette in forum C Programming
    Replies: 16
    Last Post: 04-18-2006, 03:18 AM
  5. infinity
    By Unregistered in forum C++ Programming
    Replies: 10
    Last Post: 06-01-2002, 01:35 PM

Tags for this Thread