diff --git a/libc/math/lib_libexpi.c b/libc/math/lib_libexpi.c index bcb5622130..3cd5f8f6d7 100644 --- a/libc/math/lib_libexpi.c +++ b/libc/math/lib_libexpi.c @@ -52,13 +52,12 @@ #define M_E128 (M_E64 * M_E64) #define M_E256 (M_E128 * M_E128) #define M_E512 (M_E256 * M_E256) -#define M_E1024 (M_E512 * M_E512) /**************************************************************************** * Private Data ****************************************************************************/ -static const double g_expi_square_tbl[11] = +static const double g_expi_square_tbl[] = { M_E, /* e^1 */ M_E2, /* e^2 */ @@ -69,8 +68,7 @@ static const double g_expi_square_tbl[11] = M_E64, /* e^64 */ M_E128, /* e^128 */ M_E256, /* e^256 */ - M_E512, /* e^512 */ - M_E1024, /* e^1024 */ + M_E512 /* e^512 */ }; /**************************************************************************** @@ -82,7 +80,9 @@ double lib_expi(size_t n) size_t i; double val; - if (n > 1024) + /* The largest calculable value for n is floor(ln(DBL_MAX)) */ + + if (n > 709) { return INFINITY; } diff --git a/libc/math/lib_libexpif.c b/libc/math/lib_libexpif.c index 1ab9b90f43..22c60f48d1 100644 --- a/libc/math/lib_libexpif.c +++ b/libc/math/lib_libexpif.c @@ -58,7 +58,7 @@ *(3.402823e+38). */ -static const float g_expif_square_tbl[7] = +static const float g_expif_square_tbl[] = { (float)M_E, /* e^1 */ (float)M_E2, /* e^2 */ @@ -66,7 +66,7 @@ static const float g_expif_square_tbl[7] = (float)M_E8, /* e^8 */ (float)M_E16, /* e^16 */ (float)M_E32, /* e^32 */ - (float)M_E64, /* e^64 */ + (float)M_E64 /* e^64 */ }; /**************************************************************************** @@ -78,7 +78,9 @@ float lib_expif(size_t n) size_t i; float val; - if (n >= 128) + /* The largest calculable value for n is floor(ln(FLT_MAX)) */ + + if (n > 88) { return INFINITY_F; }