On 2017-05-15 22:35:33 +0800, Liu Hao wrote: > Yeah but `printf()` from glibc doesn't think it is a NaN... From > your point of view, is this a glibc bug? I think so. If I understand correctly, the output of floating-point data in glibc is handled in stdio-common/printf_fp.c, which uses: extern mp_size_t __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size, int *expt, int *is_neg, long double value); The code is one of (not sure): sysdeps/i386/ldbl2mpn.c sysdeps/ieee754/ldbl-96/ldbl2mpn.c In sysdeps/i386/ldbl2mpn.c only, there is a special case for "pseudo zero" (no comments about the choice of the behavior, though), which was added here: commit 835abc5c0dfd1ba8aabeb52d46793b13702c708b Author: Ulrich Drepper <drepper@xxxxxxxxxx> Date: 2007-06-08 02:50:59 +0000 [BZ #4586] 2007-06-06 Jakub Jelinek <jakub@xxxxxxxxxx> BZ #4586 * sysdeps/i386/ldbl2mpn.c (__mpn_extract_long_double): Treat pseudo-zeros as zero. * sysdeps/x86_64/ldbl2mpn.c: New file. * sysdeps/ia64/ldbl2mpn.c: New file. This corresponds to Bruno Haible's bug report: https://sourceware.org/bugzilla/show_bug.cgi?id=4586 (though this was for IA64). He said: 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. Not sure about the reason of the current choice. -- Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)