diff --git a/crates/jsonschema/src/ext/numeric.rs b/crates/jsonschema/src/ext/numeric.rs index 42522694..b14261f8 100644 --- a/crates/jsonschema/src/ext/numeric.rs +++ b/crates/jsonschema/src/ext/numeric.rs @@ -66,7 +66,7 @@ pub(crate) fn is_multiple_of_float(value: &Number, multiple: f64) -> bool { if value_f64.is_zero() { return true; } - if value_f64 < multiple { + if value_f64.abs() < multiple { return false; } // From the JSON Schema spec diff --git a/crates/jsonschema/src/keywords/multiple_of.rs b/crates/jsonschema/src/keywords/multiple_of.rs index baa07974..a7162338 100644 --- a/crates/jsonschema/src/keywords/multiple_of.rs +++ b/crates/jsonschema/src/keywords/multiple_of.rs @@ -399,6 +399,7 @@ mod tests { #[test_case(&json!({"multipleOf": 0.1}), &json!(1.3))] #[test_case(&json!({"multipleOf": 0.02}), &json!(1.02))] #[test_case(&json!({"multipleOf": 1e-16}), &json!(1e-15))] + #[test_case(&json!({"multipleOf": 0.5}), &json!(-6))] fn multiple_of_is_valid(schema: &Value, instance: &Value) { tests_util::is_valid(schema, instance); }