From: Ben Pfaff Date: Sun, 28 Aug 2022 21:14:35 +0000 (-0700) Subject: dictionary: New function var_force_valid_weight(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62e7170578f4265d2baa01aaaf2ea6788fe7b4a4;hp=21767611e5b11af880714491078d57ef90fa3f91;p=pspp dictionary: New function var_force_valid_weight(). --- diff --git a/src/data/dictionary.c b/src/data/dictionary.c index c331ea2345..5fae9cf076 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -1253,7 +1253,7 @@ dict_get_weight (const struct dictionary *d) } /* Returns the value of D's weighting variable in case C, except - that a negative weight is returned as 0. Returns 1 if the + that a negative or missing weight is returned as 0. Returns 1 if the dictionary is unweighted. Will warn about missing, negative, or zero values if *WARN_ON_INVALID is true. The function will set *WARN_ON_INVALID to false if an invalid weight is @@ -1274,6 +1274,15 @@ dict_get_case_weight (const struct dictionary *d, const struct ccase *c, } } +/* Like dict_get_case_weight(), but additionally rounds each weight to the + nearest integer. */ +double +dict_get_rounded_case_weight (const struct dictionary *d, + const struct ccase *c, bool *warn_on_invalid) +{ + return floor (dict_get_case_weight (d, c, warn_on_invalid) + 0.5); +} + /* Returns the format to use for weights. */ const struct fmt_spec * dict_get_weight_format (const struct dictionary *d) diff --git a/src/data/dictionary.h b/src/data/dictionary.h index 067142cfd0..abc00062f1 100644 --- a/src/data/dictionary.h +++ b/src/data/dictionary.h @@ -98,6 +98,8 @@ void dict_set_names_must_be_ids (struct dictionary *, bool); /* Weight variable. */ double dict_get_case_weight (const struct dictionary *, const struct ccase *, bool *); +double dict_get_rounded_case_weight (const struct dictionary *, + const struct ccase *, bool *); struct variable *dict_get_weight (const struct dictionary *); void dict_set_weight (struct dictionary *, struct variable *); const struct fmt_spec *dict_get_weight_format (const struct dictionary *);