Skip to content

Nan checks for ncr and fac #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# binaries from make
bench
example
example2
example3
repl
repl-readline
smoke
smoke_pr
*.exe

# object files
*.o
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tinyexpr.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down