Skip to content

Commit cf03962

Browse files
committed
Moved pi and e into functions to allow compile time optimization.
1 parent 8e7c788 commit cf03962

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tinyexpr.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ void te_free(te_expr *n) {
9494
}
9595

9696

97-
static const double pi = 3.14159265358979323846;
98-
static const double e = 2.71828182845904523536;
97+
static double pi() {return 3.14159265358979323846;}
98+
static double e() {return 2.71828182845904523536;}
9999

100100
static const te_variable functions[] = {
101101
/* must be in alphabetical order */
@@ -107,12 +107,12 @@ static const te_variable functions[] = {
107107
{"ceil", ceil, TE_FUNCTION1 | TE_FLAG_PURE},
108108
{"cos", cos, TE_FUNCTION1 | TE_FLAG_PURE},
109109
{"cosh", cosh, TE_FUNCTION1 | TE_FLAG_PURE},
110-
{"e", &e, TE_VARIABLE},
110+
{"e", e, TE_FUNCTION0 | TE_FLAG_PURE},
111111
{"exp", exp, TE_FUNCTION1 | TE_FLAG_PURE},
112112
{"floor", floor, TE_FUNCTION1 | TE_FLAG_PURE},
113113
{"ln", log, TE_FUNCTION1 | TE_FLAG_PURE},
114114
{"log", log10, TE_FUNCTION1 | TE_FLAG_PURE},
115-
{"pi", &pi, TE_VARIABLE},
115+
{"pi", pi, TE_FUNCTION0 | TE_FLAG_PURE},
116116
{"pow", pow, TE_FUNCTION2 | TE_FLAG_PURE},
117117
{"sin", sin, TE_FUNCTION1 | TE_FLAG_PURE},
118118
{"sinh", sinh, TE_FUNCTION1 | TE_FLAG_PURE},

0 commit comments

Comments
 (0)