X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fvariable.c;h=6a00d014a18df32b7a85cb90bd3d6b3871444a7c;hb=86306a18a4933def434af0a64e22d9c13de61532;hp=971154368cb7ae5ede7b21d4f88374e6f1e4b752;hpb=0df9cdd3df66caf4353128feff3008289cda8115;p=pspp diff --git a/src/data/variable.c b/src/data/variable.c index 971154368c..6a00d014a1 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -1312,3 +1312,29 @@ var_clear_vardict (struct variable *v) { v->vardict = NULL; } + + +/* + Returns zero, if W is a missing value for WV or if it is less than zero. + Typically used to force a numerical value into a valid weight. + + As a side effect, this function will emit a warning if the value + WARN_ON_INVALID points to a bool which is TRUE. That bool will be then + set to FALSE. + */ +double +var_force_valid_weight (const struct variable *wv, double w, bool *warn_on_invalid) +{ + if (w < 0.0 || (wv && var_is_num_missing (wv, w, MV_ANY))) + w = 0.0; + + if (w == 0.0 && warn_on_invalid != NULL && *warn_on_invalid) + { + *warn_on_invalid = false; + msg (SW, _("At least one case in the data file had a weight value " + "that was user-missing, system-missing, zero, or " + "negative. These case(s) were ignored.")); + } + + return w; +}