Skip to content

Commit 6ef617f

Browse files
committed
tinyexpr: use math.h constants, constexpr
1 parent aafefb2 commit 6ef617f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/tinyexpr.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ void te_free(te_expr *n) {
123123
}
124124

125125

126-
static double pi() {return 3.14159265358979323846;}
127-
static double e() {return 2.71828182845904523536;}
128-
static double fac(double a) {/* simplest version of fac */
126+
static constexpr double pi() { return M_PI; }
127+
static constexpr double e() { return M_E; }
128+
129+
static double fac(double a) { /* simplest version of fac */
129130
if (a < 0.0)
130131
return NAN;
131132
if (a > UINT_MAX)
@@ -198,11 +199,11 @@ static const te_builtin *find_builtin(const char *name, int len) {
198199
return NULL;
199200
}
200201

201-
static double add(double a, double b) {return a + b;}
202-
static double sub(double a, double b) {return a - b;}
203-
static double mul(double a, double b) {return a * b;}
204-
static double divide(double a, double b) {return a / b;}
205-
static double negate(double a) {return -a;}
202+
static constexpr double add(double a, double b) {return a + b;}
203+
static constexpr double sub(double a, double b) {return a - b;}
204+
static constexpr double mul(double a, double b) {return a * b;}
205+
static constexpr double divide(double a, double b) {return a / b;}
206+
static constexpr double negate(double a) {return -a;}
206207

207208
void next_token(state *s) {
208209
s->type = TOK_NULL;

0 commit comments

Comments
 (0)