File tree Expand file tree Collapse file tree 6 files changed +30
-7
lines changed Expand file tree Collapse file tree 6 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,10 @@ encoding_rs = "0.8"
2323cssparser-macros = { path = " ./macros" , version = " 0.6.1" }
2424dtoa-short = " 0.3"
2525itoa = " 1.0"
26- phf = { version = " 0.11.2" , features = [" macros" ] }
26+ phf = { version = " 0.11.2" , features = [" macros" ], default-features = false }
2727serde = { version = " 1.0" , features = [" derive" ], optional = true }
2828smallvec = " 1.0"
29+ libm = " 0.2.8"
2930
3031[profile .profiling ]
3132inherits = " release"
@@ -37,7 +38,7 @@ bench = []
3738dummy_match_byte = []
3839# Useful for skipping tests when execution is slow, e.g., under miri
3940skip_long_tests = []
40- std = []
41+ std = [" phf/std " ]
4142
4243[workspace ]
4344members = [" ." , " ./macros" , " ./color" ]
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ pub fn clamp_unit_f32(val: f32) -> u8 {
4141/// Round and clamp a single number to a u8.
4242#[ inline]
4343pub fn clamp_floor_256_f32 ( val : f32 ) -> u8 {
44- val . round ( ) . clamp ( 0. , 255. ) as u8
44+ crate :: math :: f32_round ( val ) . clamp ( 0. , 255. ) as u8
4545}
4646
4747/// Serialize the alpha copmonent of a color according to the specification.
@@ -65,9 +65,9 @@ pub fn serialize_color_alpha(
6565 dest. write_str ( if legacy_syntax { ", " } else { " / " } ) ?;
6666
6767 // Try first with two decimal places, then with three.
68- let mut rounded_alpha = ( alpha * 100. ) . round ( ) / 100. ;
68+ let mut rounded_alpha = crate :: math :: f32_round ( alpha * 100. ) / 100. ;
6969 if clamp_unit_f32 ( rounded_alpha) != clamp_unit_f32 ( alpha) {
70- rounded_alpha = ( alpha * 1000. ) . round ( ) / 1000. ;
70+ rounded_alpha = crate :: math :: f32_round ( alpha * 1000. ) / 1000. ;
7171 }
7272
7373 rounded_alpha. to_css ( dest)
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ mod nth;
103103mod parser;
104104mod serializer;
105105mod unicode_range;
106+ mod math;
106107
107108#[ cfg( test) ]
108109mod size_of_tests;
Original file line number Diff line number Diff line change 1+
2+ pub ( crate ) fn f32_trunc ( val : f32 ) -> f32 {
3+ #[ cfg( feature = "std" ) ]
4+ { val. round ( ) }
5+ #[ cfg( not( feature = "std" ) ) ]
6+ { libm:: roundf ( val) }
7+ }
8+
9+ pub ( crate ) fn f32_round ( val : f32 ) -> f32 {
10+ #[ cfg( feature = "std" ) ]
11+ { val. round ( ) }
12+ #[ cfg( not( feature = "std" ) ) ]
13+ { libm:: roundf ( val) }
14+ }
15+
16+ pub ( crate ) fn f64_pow ( a : f64 , b : f64 ) -> f64 {
17+ #[ cfg( feature = "std" ) ]
18+ { f64:: powf ( a, b) }
19+ #[ cfg( not( feature = "std" ) ) ]
20+ { libm:: pow ( a, b) }
21+ }
Original file line number Diff line number Diff line change 4949 dtoa_short:: write ( dest, value) ?
5050 } ;
5151
52- if int_value. is_none ( ) && value. fract ( ) == 0. && !notation. decimal_point && !notation. scientific
52+ if int_value. is_none ( ) && value == crate :: math :: f32_trunc ( value ) && !notation. decimal_point && !notation. scientific
5353 {
5454 dest. write_str ( ".0" ) ?;
5555 }
Original file line number Diff line number Diff line change @@ -1083,7 +1083,7 @@ fn consume_numeric<'a>(tokenizer: &mut Tokenizer<'a>) -> Token<'a> {
10831083 break ;
10841084 }
10851085 }
1086- value *= f64 :: powf ( 10. , sign * exponent) ;
1086+ value *= crate :: math :: f64_pow ( 10. , sign * exponent) ;
10871087 }
10881088
10891089 let int_value = if is_integer {
You can’t perform that action at this time.
0 commit comments