File tree 6 files changed +30
-7
lines changed
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"
23
23
cssparser-macros = { path = " ./macros" , version = " 0.6.1" }
24
24
dtoa-short = " 0.3"
25
25
itoa = " 1.0"
26
- phf = { version = " 0.11.2" , features = [" macros" ] }
26
+ phf = { version = " 0.11.2" , features = [" macros" ], default-features = false }
27
27
serde = { version = " 1.0" , features = [" derive" ], optional = true }
28
28
smallvec = " 1.0"
29
+ libm = " 0.2.8"
29
30
30
31
[profile .profiling ]
31
32
inherits = " release"
@@ -37,7 +38,7 @@ bench = []
37
38
dummy_match_byte = []
38
39
# Useful for skipping tests when execution is slow, e.g., under miri
39
40
skip_long_tests = []
40
- std = []
41
+ std = [" phf/std " ]
41
42
42
43
[workspace ]
43
44
members = [" ." , " ./macros" , " ./color" ]
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ pub fn clamp_unit_f32(val: f32) -> u8 {
41
41
/// Round and clamp a single number to a u8.
42
42
#[ inline]
43
43
pub 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
45
45
}
46
46
47
47
/// Serialize the alpha copmonent of a color according to the specification.
@@ -65,9 +65,9 @@ pub fn serialize_color_alpha(
65
65
dest. write_str ( if legacy_syntax { ", " } else { " / " } ) ?;
66
66
67
67
// 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. ;
69
69
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. ;
71
71
}
72
72
73
73
rounded_alpha. to_css ( dest)
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ mod nth;
103
103
mod parser;
104
104
mod serializer;
105
105
mod unicode_range;
106
+ mod math;
106
107
107
108
#[ cfg( test) ]
108
109
mod 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 49
49
dtoa_short:: write ( dest, value) ?
50
50
} ;
51
51
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
53
53
{
54
54
dest. write_str ( ".0" ) ?;
55
55
}
Original file line number Diff line number Diff line change @@ -1087,7 +1087,7 @@ fn consume_numeric<'a>(tokenizer: &mut Tokenizer<'a>) -> Token<'a> {
1087
1087
break ;
1088
1088
}
1089
1089
}
1090
- value *= f64 :: powf ( 10. , sign * exponent) ;
1090
+ value *= crate :: math :: f64_pow ( 10. , sign * exponent) ;
1091
1091
}
1092
1092
1093
1093
let int_value = if is_integer {
You can’t perform that action at this time.
0 commit comments