Introduce support for trapping math

The feenableexcept() and fedisableexcept() APIs are now provided which
let you detect when NaNs appear the moment it happens from anywhere in
your program. Tests have also been added for the mission critical math
functions expf() and erff(), whose perfect operation has been assured.
See examples/trapping.c to see how to use this powerful functionality.
This commit is contained in:
Justine Tunney 2024-04-30 13:32:23 -07:00
parent 403bc25412
commit 5c6877b02b
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
13 changed files with 576 additions and 2 deletions

View file

@ -26,6 +26,7 @@
*/
#include "libc/errno.h"
#include "libc/cosmo.h"
#include "libc/tinymath/arm.internal.h"
#if WANT_ERRNO
@ -45,6 +46,7 @@ with_errnof (float y, int e)
dontinline static float
xflowf (uint32_t sign, float y)
{
unleaf();
y = eval_as_float (opt_barrier_float (sign ? -y : y) * y);
return with_errnof (y, ERANGE);
}
@ -74,6 +76,7 @@ __math_oflowf (uint32_t sign)
float
__math_divzerof (uint32_t sign)
{
unleaf();
float y = opt_barrier_float (sign ? -1.0f : 1.0f) / 0.0f;
return with_errnof (y, ERANGE);
}
@ -81,6 +84,7 @@ __math_divzerof (uint32_t sign)
dontinstrument float
__math_invalidf (float x)
{
unleaf();
float y = (x - x) / (x - x);
return isnan (x) ? y : with_errnof (y, EDOM);
}