From 83ec8617777cfae75b9486c9d5f96b1ad1e0042c Mon Sep 17 00:00:00 2001 From: Juho Eerola Date: Mon, 26 Jul 2021 05:03:10 +0300 Subject: [PATCH 1/2] Add NAN check to ncr and fac Now both `fac` and `ncr` will return NAN, if any argument is NAN. --- tinyexpr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 tinyexpr.c diff --git a/tinyexpr.c b/tinyexpr.c old mode 100755 new mode 100644 index a5fc9d8..3877927 --- a/tinyexpr.c +++ b/tinyexpr.c @@ -122,7 +122,7 @@ void te_free(te_expr *n) { static double pi(void) {return 3.14159265358979323846;} static double e(void) {return 2.71828182845904523536;} static double fac(double a) {/* simplest version of fac */ - if (a < 0.0) + if (a < 0.0 || isnan(a)) return NAN; if (a > UINT_MAX) return INFINITY; @@ -136,7 +136,7 @@ static double fac(double a) {/* simplest version of fac */ return (double)result; } static double ncr(double n, double r) { - if (n < 0.0 || r < 0.0 || n < r) return NAN; + if (n < 0.0 || r < 0.0 || n < r || isnan(n) || isnan(r)) return NAN; if (n > UINT_MAX || r > UINT_MAX) return INFINITY; unsigned long int un = (unsigned int)(n), ur = (unsigned int)(r), i; unsigned long int result = 1; From 7fe2a4e597eb9cce09d7f410a4bfc5da76efe60d Mon Sep 17 00:00:00 2001 From: Juho Eerola Date: Mon, 26 Jul 2021 05:43:08 +0300 Subject: [PATCH 2/2] Add .gitignore Ignore object files and executables from make targets. Also added repl-readline to make clean target. --- .gitignore | 13 +++++++++++++ Makefile | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..043300a --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# binaries from make +bench +example +example2 +example3 +repl +repl-readline +smoke +smoke_pr +*.exe + +# object files +*.o diff --git a/Makefile b/Makefile index d3db7cf..c933ecc 100644 --- a/Makefile +++ b/Makefile @@ -40,4 +40,4 @@ repl-readline.o: repl.c $(CC) -c $(CCFLAGS) $< -o $@ clean: - rm -f *.o *.exe example example2 example3 bench repl smoke_pr smoke + rm -f *.o *.exe example example2 example3 bench repl repl-readline smoke_pr smoke