Skip to content
Open
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
7 changes: 4 additions & 3 deletions tinyexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ typedef struct state {
static te_expr *new_expr(const int type, const te_expr *parameters[]) {
const int arity = ARITY(type);
const int psize = sizeof(void*) * arity;
const int size = (sizeof(te_expr) - sizeof(void*)) + psize + (IS_CLOSURE(type) ? sizeof(void*) : 0);
int size = (sizeof(te_expr) - sizeof(void*)) + psize + (IS_CLOSURE(type) ? sizeof(void*) : 0);
if (size < (int)sizeof(te_expr)) size = sizeof(te_expr);
te_expr *ret = malloc(size);
CHECK_NULL(ret);

Expand Down Expand Up @@ -125,7 +126,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))
return NAN;
if (a > UINT_MAX)
return INFINITY;
Expand All @@ -139,7 +140,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) 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