[PATCH] Remove matherr, and SVID and X/Open math library configurations

Craig Howland howland@LGSInnovations.com
Tue Jan 22 22:27:00 GMT 2019

On 1/22/19 3:51 PM, Jozef Lawrynowicz wrote:
> ...
> I've attached the original patch (0001-*), but also 3 further patches which
> make some additional improvements to the float math functions.
> 0002-Newlib-Remove-HUGE_VAL-definition-from-libm-math-fun.patch
> This patch removes the definitions of HUGE_VAL from some of the float math
> functions. HUGE_VAL is defined in newlib/libc/include/math.h, so it is not
> necessary to have a further definition in the math functions.
> 0003-Newlib-Use-HUGE_VALF-instead-of-HUGE_VAL-in-single-p.patch
> This patch replaces instances of "(float).*HUGE_VAL" with a direct usage of
> HUGE_VALF, which is also defined in math.h.
> 0004-Newlib-Use-nanf-instead-of-nan-in-single-precision-f.patch
> This patch further reduces code size for a few single-precision float math
> functions, by using nanf() instead of nan() where required.
> I've regtested the patches with the GCC testsuite for arm-unknown-eabi, and I
> built Cygwin and regtested it with "make check".
> Thanks,
> Jozef
      The tgamma() return values don't match the POSIX recommendation.  This is 
not really the fault of this patch, but the patch is propagating mistakes in the 
existing __kernel_standard() function (in k_standard.c).  POSIX defines a domain 
error for negative integers, with errno=EDOM return NAN.  This case is 
identified by value 41 to __kernel_standard(), except that it is also grouped 
with the case of tgamma(0).  tgamma(+-0) is a pole error, errno=ERANGE return 
+-HUGE_VAL, with the sign matching the argument.  In addition, an overflow error 
(value 40 to __kernel_standard()) is supposed to match the sign. That is, the 
existing implementation has several mistakes in it which are being propagated in 
the revised implementation.  Put another way, there are 3 different error 
classes, yet __kernel_standard() only has 2 that are used by tgamma().
      Speaking of the __kernel_standard() function, it really would best be 
deleted.  It is only called from tgamma() and tgammaf(), and could therefore 
stand a very large pruning, at the least.  But rather than that, just getting 
rid of it seems to be in order because the entire purpose behind 
__kernel_standard() appears to be related to the matherr stuff being deleted, 
and fixing the aforementioned tgamma() return-value problems would be more 
easily done within the functions than expanding __kernel_standard(), anyway.
      These comments are really about existing flaws and not flaws in this 
patch, but it does seem a good opportunity to take care of them.
      (I did not look over the whole patch in detail, but happened to find this 
due to curiosity about the funky __kernel_standard() function.  From a high 
level it appears good.)


More information about the Newlib mailing list