Skip to content
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
Binary file added example.exe
Binary file not shown.
1 change: 1 addition & 0 deletions tempCodeRunnerFile.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main
14 changes: 12 additions & 2 deletions tinyexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,29 @@ static double fac(double a) {/* simplest version of fac */
return (double)result;
}
static double ncr(double n, double r) {
if (!isfinite(n) || !isfinite(r)) return NAN;

if (n < 0.0 || r < 0.0 || n < 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 un = (unsigned int)(n);
unsigned long int ur = (unsigned int)(r);
unsigned long int i;

unsigned long int result = 1;

if (ur > un / 2) ur = un - ur;

for (i = 1; i <= ur; i++) {
if (result > ULONG_MAX / (un - ur + i))
return INFINITY;
result *= un - ur + i;
result /= i;
}

return result;
}

static double npr(double n, double r) {return ncr(n, r) * fac(r);}

#ifdef _MSC_VER
Expand Down Expand Up @@ -256,7 +266,7 @@ void next_token(state *s) {
const char *start;
start = s->next;
while (isalpha(s->next[0]) || isdigit(s->next[0]) || (s->next[0] == '_')) s->next++;

const te_variable *var = find_lookup(s, start, s->next - start);
if (!var) var = find_builtin(start, s->next - start);

Expand Down