From: John Darrington Date: Sat, 20 Jun 2020 05:17:06 +0000 (+0200) Subject: find-dialog.c: Replace exp10 with our own integer version X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04961f63d4ca08a9699c9b4f6a02f49db960682c;p=pspp find-dialog.c: Replace exp10 with our own integer version A previous commit introduced the use of exp10 from the standard math library. However the use cases here don't need floating point operands, and it's smaller and faster to implement our own integer version. --- diff --git a/src/ui/gui/find-dialog.c b/src/ui/gui/find-dialog.c index 2ff619a60a..e617280739 100644 --- a/src/ui/gui/find-dialog.c +++ b/src/ui/gui/find-dialog.c @@ -452,6 +452,18 @@ struct regexp_comparator regex_t re; }; +/* Returns 10 raised to the power of X. + X must be a non-negative integer. */ +static inline int +int_pow10 (int x) +{ + int ret = 1; + assert (x >= 0); + while (x--) + ret *= 10; + + return ret; +} static bool value_compare (const struct comparator *cmptr, @@ -460,7 +472,7 @@ value_compare (const struct comparator *cmptr, const struct numeric_comparator *nc = (const struct numeric_comparator *) cmptr; const struct fmt_spec *fs = var_get_print_format (cmptr->var); - double c = nearbyint (v->f * exp10 (fs->d)); + double c = nearbyint (v->f * int_pow10 (fs->d)); return c == nc->rounded_ref; } @@ -592,7 +604,7 @@ numeric_comparator_create (const struct variable *var, const char *target) union value val; text_to_value (target, var, &val); - nc->rounded_ref = nearbyint (val.f * exp10 (fs->d)); + nc->rounded_ref = nearbyint (val.f * int_pow10 (fs->d)); value_destroy (&val, var_get_width (var)); return cmptr;