Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func Validate(r Registry, s *Schema, path *PathBuffer, mode ValidateMode, v any,
}
}
if s.MultipleOf != nil {
if math.Mod(num, *s.MultipleOf) != 0 {
if r := math.Mod(num, *s.MultipleOf); math.Abs(r) > 1e-9 && math.Abs(r-*s.MultipleOf) > 1e-9 {
res.Add(path, v, s.msgMultipleOf)
}
}
Expand Down
7 changes: 7 additions & 0 deletions validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ var validateTests = []struct {
input: map[string]any{"value": 2},
errs: []string{"expected number to be a multiple of 5"},
},
{
name: "multiple of float success",
typ: reflect.TypeFor[struct {
Value float64 "json:\"value\" multipleOf:\"0.01\""
}](),
input: map[string]any{"value": 0.36},
},
{
name: "string success",
typ: reflect.TypeFor[string](),
Expand Down