Procházet zdrojové kódy

sh: give FP_ILOGB0 the type ISO C asks for

sh was the only port to write these as hexadecimal:

	# define FP_ILOGB0	0x80000001
	# define FP_ILOGBNAN	0x7fffffff

0x80000001 does not fit in an int, so it has type unsigned int and the
value 2147483649, where ISO C 7.12 wants FP_ILOGB0 to expand to INT_MIN
or -INT_MAX.  The macro then contradicts itself: libm/s_ilogb.c returns
it from a function declared int, so ilogb(0) hands back -2147483647,
while a program comparing against the macro is comparing with 2147483649.
That is what the ilogb test reports on sh4, at -O0 and at -O2:

  FAIL: ilogb(0/00000000)=-2147483647/18446744071562067969
        (expected 2147483649)

Use the decimal form the other fifteen ports use.  The runtime value does
not change -- 0x80000001 converted to int was already -2147483647 -- so
this is the type and nothing else.  FP_ILOGBNAN goes with it for
symmetry; 0x7fffffff fits in an int and was never wrong.

Built for sh4 and run under qemu-sh4: the test passes at both
optimisation levels with the change and, with the old macro put back into
the installed header, fails with exactly the two lines above.

Signed-off-by: Ramin Moussavi <lordrasmus@gmail.com>
ramin před 3 dny
rodič
revize
644fe9aaa2
1 změnil soubory, kde provedl 6 přidání a 3 odebrání
  1. 6 3
      libc/sysdeps/linux/sh/bits/mathdef.h

+ 6 - 3
libc/sysdeps/linux/sh/bits/mathdef.h

@@ -35,9 +35,12 @@ typedef float float_t;		/* `float' expressions are evaluated as
 typedef double double_t;	/* `double' expressions are evaluated as
 				   `double'.  */
 
-/* The values returned by `ilogb' for 0 and NaN respectively.  */
-# define FP_ILOGB0	0x80000001
-# define FP_ILOGBNAN	0x7fffffff
+/* The values returned by `ilogb' for 0 and NaN respectively.  ISO C wants
+   these to be int, and 0x80000001 does not fit in one, so it used to be
+   unsigned: ilogb(0) returned -2147483647 while the macro compared equal to
+   2147483649.  */
+# define FP_ILOGB0	(-2147483647)
+# define FP_ILOGBNAN	2147483647
 
 #endif	/* ISO C99 */