Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's a shame that -fno-math-errno isn't the default. It pessimizes many common operations, as can be seen in the article. Also e.g. a simple sqrt() call like

#include <math.h>

double mysqrt(double d) { return sqrt(d); }

with and without -fno-math-errno: https://godbolt.org/z/bvrz9r8ce

One can see that with -fno-math-errno the function can be entirely inlined. But if errno is enabled, it has to first check whether the input is negative, and in that case call the libc sqrt() function which sets errno.

As for why it's not the default, I guess it's historical. The errno approach was common back in the days before IEEE 754 with its exception model provided another way.

E.g. for glibc: https://man7.org/linux/man-pages/man7/math_error.7.html

Musl libc, being newer, does away with that and never sets errno in libm functions: https://wiki.musl-libc.org/mathematical-library.html



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: