mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
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:
parent
403bc25412
commit
5c6877b02b
13 changed files with 576 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue