From 3bf905692c9db5309c5cd4c0dec7ec17ab8c7af1 Mon Sep 17 00:00:00 2001 From: David Rowley Date: Wed, 8 Oct 2025 12:07:17 +1300 Subject: [PATCH] Cleanup INFINITY code in float.h The INFINITY macro is always defined per C99 standard, so this should mean we can now get rid of the workaround code for when that macro isn't defined. Also, delete the (now unneeded) #pragma code which was disabling a compiler warning in MSVC. There was a comment explaining why the #pragma was placed outside the function body to work around a MSVC compiler bug, but the link explaining that was dead, as reported by jian he. Author: David Rowley Reported-by: jian he Reviewed-by: Tom Lane Discussion: https://postgr.es/m/CACJufxGARYETnNwtCK7QC0zE_7gq-tfN0mME=gT5rTNtC=VSHQ@mail.gmail.com --- src/include/utils/float.h | 49 ++++++--------------------------------- 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/src/include/utils/float.h b/src/include/utils/float.h index 0e2e9ec5347..fa903b4bf59 100644 --- a/src/include/utils/float.h +++ b/src/include/utils/float.h @@ -51,62 +51,27 @@ extern char *float8out_internal(float8 num); extern int float4_cmp_internal(float4 a, float4 b); extern int float8_cmp_internal(float8 a, float8 b); -/* - * Routines to provide reasonably platform-independent handling of - * infinity and NaN - * - * We assume that isinf() and isnan() are available and work per spec. - * (On some platforms, we have to supply our own; see src/port.) However, - * generating an Infinity or NaN in the first place is less well standardized; - * pre-C99 systems tend not to have C99's INFINITY and NaN macros. We - * centralize our workarounds for this here. - */ - -/* - * The funny placements of the two #pragmas is necessary because of a - * long lived bug in the Microsoft compilers. - * See http://support.microsoft.com/kb/120968/en-us for details - */ -#ifdef _MSC_VER -#pragma warning(disable:4756) -#endif static inline float4 get_float4_infinity(void) { -#ifdef INFINITY /* C99 standard way */ return (float4) INFINITY; -#else -#ifdef _MSC_VER -#pragma warning(default:4756) -#endif - - /* - * On some platforms, HUGE_VAL is an infinity, elsewhere it's just the - * largest normal float8. We assume forcing an overflow will get us a - * true infinity. - */ - return (float4) (HUGE_VAL * HUGE_VAL); -#endif } static inline float8 get_float8_infinity(void) { -#ifdef INFINITY /* C99 standard way */ return (float8) INFINITY; -#else - - /* - * On some platforms, HUGE_VAL is an infinity, elsewhere it's just the - * largest normal float8. We assume forcing an overflow will get us a - * true infinity. - */ - return (float8) (HUGE_VAL * HUGE_VAL); -#endif } +/* + * Routines to provide reasonably platform-independent handling of NaN + * + * We assume that isnan() is available and work per spec. However, generating + * a NaN in the first place is less well standardized; pre-C99 systems tend + * not to have C99's NaN macro. We centralize our workaround for this here. + */ static inline float4 get_float4_nan(void) { -- 2.47.3