summaryrefslogtreecommitdiffstats
path: root/lib/factorial.c
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-08-09 15:02:21 +0400
committerEthan Werner <mail@ethanwerner.com>2026-08-09 15:02:21 +0400
commit3d92926a902017e7cf1f5738e99ff62da596ce12 (patch)
tree2b55422c26a48759d56fa91f06df24449e9dfa88 /lib/factorial.c
parent07e18043145f3d91c8ea7ec3ad41b3c905585277 (diff)
Diffstat (limited to 'lib/factorial.c')
-rw-r--r--lib/factorial.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/factorial.c b/lib/factorial.c
index 8e64fa3..7e82ffb 100644
--- a/lib/factorial.c
+++ b/lib/factorial.c
@@ -8,6 +8,7 @@
// Outputs: 1 (n!)
// Constants: 0
+#include <math.h>
#include "ts.h"
@@ -31,7 +32,7 @@ int ts_factorial(
(void)c;
for( uint_t i = 0; i < n; ++i )
{
- if (x[0][i] < 0) { y[0][i] = NAN; continue; }
+ if (isnan(x[0][i]) || isinf(x[0][i]) || x[0][i] < 0) { y[0][i] = NAN; continue; }
fp_t result = 1.0;
uint_t k = (uint_t)x[0][i];
if (k > 170) k = 170;