From 5012fb0e3642839c6855b67982621f875340c7e0 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 1 Dec 2018 13:25:00 -0800 Subject: [PATCH] Add 'round' function to builtin math --- src/tinyexpr.c | 1 + tests/math.err | 3 +++ tests/math.in | 4 ++++ tests/math.out | 9 +++++++++ 4 files changed, 17 insertions(+) diff --git a/src/tinyexpr.c b/src/tinyexpr.c index a2ef44a77..f53a5d574 100755 --- a/src/tinyexpr.c +++ b/src/tinyexpr.c @@ -150,6 +150,7 @@ static const te_variable functions[] = { {"npr", npr, TE_FUNCTION2 | TE_FLAG_PURE, 0}, {"pi", pi, TE_FUNCTION0 | TE_FLAG_PURE, 0}, {"pow", pow, TE_FUNCTION2 | TE_FLAG_PURE, 0}, + {"round", round, TE_FUNCTION1 | TE_FLAG_PURE, 0}, {"sin", sin, TE_FUNCTION1 | TE_FLAG_PURE, 0}, {"sinh", sinh, TE_FUNCTION1 | TE_FLAG_PURE, 0}, {"sqrt", sqrt, TE_FUNCTION1 | TE_FLAG_PURE, 0}, diff --git a/tests/math.err b/tests/math.err index 2a42d8ebc..6d4dcc1ca 100644 --- a/tests/math.err +++ b/tests/math.err @@ -2,6 +2,9 @@ #################### # Validate basic expressions +#################### +# Validate some rounding functions + #################### # Validate some integral computations diff --git a/tests/math.in b/tests/math.in index aaf515d39..48c0afd44 100644 --- a/tests/math.in +++ b/tests/math.in @@ -15,6 +15,10 @@ math 5 \* -2 math -- -4 / 2 math -- '-4 * 2' +logmsg Validate some rounding functions +math 'round(3/2)' ; math 'floor(3/2)' ; math 'ceil(3/2)' +math 'round(-3/2)' ; math 'floor(-3/2)' ; math 'ceil(-3/2)' + logmsg Validate some integral computations math 1 math 10 diff --git a/tests/math.out b/tests/math.out index 4cafd7a30..1f385b54c 100644 --- a/tests/math.out +++ b/tests/math.out @@ -17,6 +17,15 @@ -2 -8 +#################### +# Validate some rounding functions +2 +1 +2 +-2 +-2 +-1 + #################### # Validate some integral computations 1