standards/127795: [patch] INFINITY and INF have wrong type

Christoph Mallon christoph.mallon at gmx.de
Thu Oct 2 07:50:06 UTC 2008


>Number:         127795
>Category:       standards
>Synopsis:       [patch] INFINITY and INF have wrong type
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-standards
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 02 07:50:05 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Christoph Mallon
>Release:        n/a
>Organization:
>Environment:
n/a
>Description:
INFINITY and NAN are defined as __builtin_inf() resp. __builtin_nan(), which both return a double result. But the C99 standard mandates that INFINITY and NAN are of type float (ISO/IEC 9899:1999(E) 7.12 clause 4 and 5).
>How-To-Repeat:
This test program prints "bad" for both INFINITY and NAN:

#include <math.h>
#include <stdio.h>

int main(void)
{
  printf("INFINITY %s NAN %s\n",
    sizeof(INFINITY) == sizeof(float) ? "good" : "bad",
    sizeof(NAN)      == sizeof(float) ? "good" : "bad");
  return 0;
}
>Fix:
Change the macro definitions to use __builtin_inff() resp. __builtin_nanf(). See attachment.

Patch attached with submission follows:

Index: lib/msun/src/math.h
===================================================================
--- lib/msun/src/math.h	(Revision 183225)
+++ lib/msun/src/math.h	(Arbeitskopie)
@@ -55,8 +55,8 @@
 #ifdef __MATH_BUILTIN_CONSTANTS
 #define	HUGE_VALF	__builtin_huge_valf()
 #define	HUGE_VALL	__builtin_huge_vall()
-#define	INFINITY	__builtin_inf()
-#define	NAN		__builtin_nan("")
+#define	INFINITY	__builtin_inff()
+#define	NAN		__builtin_nanf("")
 #else
 #define	HUGE_VALF	(float)HUGE_VAL
 #define	HUGE_VALL	(long double)HUGE_VAL


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-standards mailing list