crepl

An intuitive calculator REPL.
git clone git://git.knutsen.co/crepl
Log | Files | Refs | README | LICENSE

commit f5082c2fc369c8f78d11ddbe25829866b21855ed
parent c03f80677c5cbd132894a512172ce54548ed8cc9
Author: Demonstrandum <moi@knutsen.co>
Date:   Sat, 27 Jun 2020 09:47:08 +0100

Give sin a "prettier" (technically less accurate) output.

Diffstat:
Msrc/builtin.c | 17++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/builtin.c b/src/builtin.c @@ -94,7 +94,18 @@ DataValue *builtin_ ##NAME (DataValue input) \ return result; \ } -MATH_WRAPPER(sin, sinl) +// This is cheaty, but hey oh. +fsize nice_sin(fsize alpha) +{ + fsize multiples_of_pi = alpha / M_PI; + fsize integral = 0; + fsize fractional = modfl(multiples_of_pi, &integral); + if (fractional == 0.0f) // i.e. if alpha/pi is a whole number... + return 0.0f; + return sin(alpha); +} + +MATH_WRAPPER(sin, nice_sin) MATH_WRAPPER(sinh, sinhl) MATH_WRAPPER(cos, cosl) MATH_WRAPPER(cosh, coshl) @@ -149,8 +160,8 @@ DataValue *builtin_factorial(DataValue input) if (num == NULL) return NULL; - f32 integral = 0; - f32 fractional = modff(num->value.f, &integral); + fsize integral = 0; + fsize fractional = modfl(num->value.f, &integral); if ((num->type == FLOAT && (fractional != 0 || num->value.f < 0)) || (num->type == INT && num->value.i < 0)) { ERROR_TYPE = EXECUTION_ERROR;