File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,10 @@ edition = "2018"
66
77[dependencies ]
88paste = " 0.1"
9+ num-traits = { version = " 0.2" , optional = true , default-features = false }
910
1011[features ]
1112default = [" std" ]
12- std = []
13+ std = []
14+ # Enables converting values to floats in no-`std` environment
15+ float = [" num-traits" ]
Original file line number Diff line number Diff line change @@ -203,9 +203,20 @@ pub struct NumberValue {
203203 pub exponent : i32 ,
204204}
205205
206- #[ cfg( feature = "std" ) ]
206+ impl NumberValue {
207+ /// Losslessly convert the inner value to `f64`.
208+ #[ cfg( any( feature = "std" , feature = "float" ) ) ]
209+ pub fn to_f64 ( self ) -> f64 {
210+ self . into ( )
211+ }
212+ }
213+
214+ #[ cfg( any( feature = "std" , feature = "float" ) ) ]
207215impl Into < f64 > for NumberValue {
208216 fn into ( self ) -> f64 {
217+ #[ cfg( not( feature = "std" ) ) ]
218+ use num_traits:: float:: FloatCore as _;
219+
209220 ( self . integer as f64 + self . fraction as f64 / 10f64 . powi ( self . fraction_length as i32 ) )
210221 * 10f64 . powi ( self . exponent )
211222 }
You can’t perform that action at this time.
0 commit comments