File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,17 @@ impl Number {
279
279
}
280
280
}
281
281
282
+ pub ( crate ) fn as_f32 ( & self ) -> Option < f32 > {
283
+ #[ cfg( not( feature = "arbitrary_precision" ) ) ]
284
+ match self . n {
285
+ N :: PosInt ( n) => Some ( n as f32 ) ,
286
+ N :: NegInt ( n) => Some ( n as f32 ) ,
287
+ N :: Float ( n) => Some ( n as f32 ) ,
288
+ }
289
+ #[ cfg( feature = "arbitrary_precision" ) ]
290
+ self . n . parse :: < f32 > ( ) . ok ( ) . filter ( |float| float. is_finite ( ) )
291
+ }
292
+
282
293
pub ( crate ) fn from_f32 ( f : f32 ) -> Option < Number > {
283
294
if f. is_finite ( ) {
284
295
let n = {
Original file line number Diff line number Diff line change @@ -9,6 +9,13 @@ fn eq_u64(value: &Value, other: u64) -> bool {
9
9
value. as_u64 ( ) . map_or ( false , |i| i == other)
10
10
}
11
11
12
+ fn eq_f32 ( value : & Value , other : f32 ) -> bool {
13
+ match value {
14
+ Value :: Number ( n) => n. as_f32 ( ) . map_or ( false , |i| i == other) ,
15
+ _ => false ,
16
+ }
17
+ }
18
+
12
19
fn eq_f64 ( value : & Value , other : f64 ) -> bool {
13
20
value. as_f64 ( ) . map_or ( false , |i| i == other)
14
21
}
@@ -90,6 +97,7 @@ macro_rules! partialeq_numeric {
90
97
partialeq_numeric ! {
91
98
eq_i64[ i8 i16 i32 i64 isize ]
92
99
eq_u64[ u8 u16 u32 u64 usize ]
93
- eq_f64[ f32 f64 ]
100
+ eq_f32[ f32 ]
101
+ eq_f64[ f64 ]
94
102
eq_bool[ bool ]
95
103
}
You can’t perform that action at this time.
0 commit comments