File tree 1 file changed +4
-17
lines changed
1 file changed +4
-17
lines changed Original file line number Diff line number Diff line change @@ -109,23 +109,10 @@ impl Validator for ConstrainedFloatValidator {
109
109
return Err ( ValError :: new ( ErrorTypeDefaults :: FiniteNumber , input) ) ;
110
110
}
111
111
if let Some ( multiple_of) = self . multiple_of {
112
- const EPSILON_FACTOR : f64 = 100.0 ;
113
- let epsilon_threshold = f64:: EPSILON * EPSILON_FACTOR ;
114
-
115
- // Round the result of dividing the input value by the multiple
116
- let rounded = ( float / multiple_of) . round ( ) ;
117
-
118
- // Calculate the difference between the rounded value and the original value
119
- let diff = ( float - rounded * multiple_of) . abs ( ) ;
120
-
121
- // Calculate the relative error (avoid division by zero)
122
- let relative_error = if float != 0.0 { diff / float. abs ( ) } else { 0.0 } ;
123
-
124
- // Threshold (considering both relative and absolute error)
125
- let threshold = epsilon_threshold. max ( multiple_of * epsilon_threshold) ;
126
-
127
- // Check if the difference exceeds the threshold and the relative error is significant
128
- if diff > threshold && relative_error > epsilon_threshold {
112
+ let tolerance = 1e-9 ;
113
+ let rounded_div = ( float / multiple_of) . round ( ) ;
114
+ let diff = ( float - ( rounded_div * multiple_of) ) . abs ( ) ;
115
+ if diff > tolerance {
129
116
return Err ( ValError :: new (
130
117
ErrorType :: MultipleOf {
131
118
multiple_of : multiple_of. into ( ) ,
You can’t perform that action at this time.
0 commit comments