Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accuracy requirement of GNU GCC math functions?

I have tried in vain for several days to find the accuracy of Math functions(in math.h) of GNU GCC compiler. C99 standard says that the accuracy requirement of Math functions in math.h is implementation defined. I could not find any mention about this in the GNU GCC compiler manuals. Does anyone have a answer to this ?

like image 589
user1200373 Avatar asked Feb 09 '12 18:02

user1200373


People also ask

Does GCC use IEEE 754?

The GCC port for AArch64 only supports the IEEE 754-2008 format, and does not require use of the -mfp16-format command-line option.

What is __ Builtin_ffs?

Built-in Function: int __builtin_ffs (int x) Returns one plus the index of the least significant 1-bit of x , or if x is zero, returns zero. Built-in Function: int __builtin_clz (unsigned int x) Returns the number of leading 0-bits in x , starting at the most significant bit position.

What is GCC do?

It functions as a cross compiler, creating executable code for a platform other than the one on which the compiler is running. GCC is also a core component of the tightly integrated GNU toolchain, produced by the GNU Project, that includes glibc, Binutils, and the GNU Debugger (GDB).


3 Answers

The math.h functions are part of the GNU C Library, not the GCC compiler. Their accuracy is documented here, as part of the GNU C Library manual.

like image 178
Josh Kelley Avatar answered Oct 14 '22 16:10

Josh Kelley


The only safe thing to assume is that the '-' characters in the glibc math accuracy chart:

http://www.gnu.org/software/libc/manual/html_node/Errors-in-Math-Functions.html#Errors-in-Math-Functions

mean "not tested", given the lack of official documentation suggesting otherwise.

like image 44
James Paul Turner Avatar answered Oct 14 '22 15:10

James Paul Turner


The errors are indeed listed here, but IMHO the assumption that "-" means "correctly rounded" (i.e. 1/2 ulp) is almost certainly refuted by the statement at the top of the page

[T]he GNU C Library does not aim for correctly rounded results for functions in the math library ... Instead, the goals for accuracy of functions without fully specified results are as follows; some functions have bugs meaning they do not meet these goals in all cases. In future, the GNU C Library may provide some other correctly rounding functions under the names such as crsin proposed for an extension to ISO C.

After researching the source code a bit, I found what appears to be the results of a ulp test (for x86-64). It looks like, for the default rounding mode (round to nearest, ties go to even), they only explicitly test double when the ulp of long double (80 bit IEEE) is worse than float. The implicit assumption seems to be that double can't be worse than long double. For the directed rounding modes, they seem to always test both float and double explicitly.

There is some weirdness, though.

  • There are no test results listed for exp.
  • For cos and tan, they only test real/complex long double.
like image 1
Keith Pedersen Avatar answered Oct 14 '22 16:10

Keith Pedersen