This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/4586] New: printf crashes on some 'long double' values
- From: "bruno at clisp dot org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 2 Jun 2007 23:29:13 -0000
- Subject: [Bug libc/4586] New: printf crashes on some 'long double' values
- Reply-to: sourceware-bugzilla at sourceware dot org
This program crashes inside printf of a pseudo-zero 'long double' number.
============================== ia64nan.c ================================
#include <float.h>
#include <math.h>
#include <stdio.h>
union u { unsigned int word[4]; long double value; };
#define X x.value
void test (const char *label, union u x)
{
printf ("%s:\n", label);
printf ("isnanl: %d %d %d\n", isnanl(X) != 0, !(X == X), !(X >= 0 || X <= 0));
printf ("isinfl: %d %d\n", isinfl(X) != 0, X + X == X && !(X == 0));
printf ("printf: %Le %Lg\n", X, X);
printf ("printf normalized: %Lg\n", X * 1.0L);
printf ("\n");
}
int main ()
{
{
union u x = { { 0x00000000, 0x63333333, 0x00008000, 0x00000000 } };
test ("unnormalized number", x);
}
{
union u x = { { 0x00000000, 0xC3333333, 0x0000FFFF, 0x00000000 } };
test ("QNaN", x);
}
{
union u x = { { 0x00000000, 0x83333333, 0x0000FFFF, 0x00000000 } };
test ("SNaN", x);
}
{
union u x = { { 0x00000000, 0x80000000, 0x0000FFFF, 0x00000000 } };
test ("Inf", x);
}
{
union u x = { { 0x00000000, 0x40000001, 0x0000ffff, 0x00000000 } };
test ("Pseudo-NaN", x);
}
{
union u x = { { 0x00000000, 0x00000000, 0x0000ffff, 0x00000000 } };
test ("Pseudo-Inf", x);
}
{
union u x = { { 0x00000000, 0x00000000, 0x00008004, 0x00000000 } };
test ("Pseudo-Zero", x);
}
return 0;
}
=========================================================================
$ gcc -O -fno-builtin -Wall ia64nan.c
$ ./a.out
unnormalized number:
isnanl: 0 0 0
isinfl: 0 0
printf: -2.605630e-4932 -2.60563e-4932
printf normalized: -2.60563e-4932
QNaN:
isnanl: 1 1 1
isinfl: 0 0
printf: nan nan
printf normalized: nan
SNaN:
isnanl: 1 1 1
isinfl: 0 0
printf: nan nan
printf normalized: nan
Inf:
isnanl: 0 0 0
isinfl: 1 1
printf: -inf -inf
printf normalized: -inf
Pseudo-NaN:
isnanl: 0 1 1
isinfl: 0 0
printf: -5.948657e+4931 -5.94866e+4931
printf normalized: -5.94866e+4931
Pseudo-Inf:
isnanl: 0 1 1
isinfl: 0 0
printf: -0.000000e+4912 -0e+4912
printf normalized: -0e+4912
Pseudo-Zero:
isnanl: 0 0 0
isinfl: 0 0
Segmentation fault
According to
Intel IA-64 Architecture Software Developer's Manual, Volume 1:
Application Architecture.
5.1.3 "Representation of Values in Floating-Point Registers"
Table 5-2 "Floating-Point Register Encodings"
Figure 5-11 "Floating-Point Exception Fault Prioritization"
pseudo-NaNs, pseudo-Infs, pseudo-zeroes "are never produced as a result
of an arithmetic operation", i.e. they may be considered to live outside
the IRRR 754 range of numbers. But it would be nice if printf would not
crash here, because
1) printf is often used for debugging. This is also the reason why
printf("%s", NULL) prints "(null)" instead of crashing.
2) Arithmetic operations on pseudo-NaNs, pseudo-Infs, pseudo-zeroes
don't cause program crashes, if operations on "signalling NaNs"
don't cause program crashes (see Figure 5-11, cited above); this
is the default behaviour, as you can see from the program's output.
Additionally, the printf results for pseudo-NaN and pseudo-Inf should better
be "nan", because these numbers behave like NaNs in comparisons, as you can
see from the program's output.
For comparison: On FreeBSD/ia64, printf of pseudo-NaN, pseudo-Inf, pseudo-zero
yields "nan", "[-]inf", "[-]0" respectively.
--
Summary: printf crashes on some 'long double' values
Product: glibc
Version: 2.3.6
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: bruno at clisp dot org
CC: glibc-bugs at sources dot redhat dot com
GCC build triplet: ia64-unknown-linux-gnu
GCC host triplet: ia64-unknown-linux-gnu
GCC target triplet: ia64-unknown-linux-gnu
http://sourceware.org/bugzilla/show_bug.cgi?id=4586
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.