Fix non_negative validator to allow 0.0

This commit is contained in:
Jeff Epler 2023-04-23 09:28:34 -05:00
parent c4104898ce
commit ca6ea83ff5
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE

View File

@ -204,8 +204,8 @@ void mp_arg_validate_obj_float_range(mp_obj_t float_in, mp_int_t min, mp_int_t m
mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t default_for_null, qstr arg_name) { mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t default_for_null, qstr arg_name) {
const mp_float_t f = (float_in == MP_OBJ_NULL) const mp_float_t f = (float_in == MP_OBJ_NULL)
? default_for_null ? default_for_null
: mp_obj_get_float(float_in); : mp_arg_validate_type_float(float_in, arg_name);
if (f <= (mp_float_t)0.0) { if (f < (mp_float_t)0.0) {
mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, 0); mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, 0);
} }
return f; return f;