Skip to content

Commit 47c72fa

Browse files
ErichDonGublercwfitzgerald
authored andcommitted
fix(wgsl-in,const-eval): use {float}::round_ties_even instead of polyfill for round
1 parent 45b0df6 commit 47c72fa

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

naga/src/proc/constant_evaluator.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,30 +1201,7 @@ impl<'a> ConstantEvaluator<'a> {
12011201
component_wise_float!(self, span, [arg], |e| { Ok([e.floor()]) })
12021202
}
12031203
crate::MathFunction::Round => {
1204-
// TODO: this hit stable on 1.77, but MSRV hasn't caught up yet
1205-
// This polyfill is shamelessly [~~stolen from~~ inspired by `ndarray-image`][polyfill source],
1206-
// which has licensing compatible with ours. See also
1207-
// <https://github.com/rust-lang/rust/issues/96710>.
1208-
//
1209-
// [polyfill source]: https://github.com/imeka/ndarray-ndimage/blob/8b14b4d6ecfbc96a8a052f802e342a7049c68d8f/src/lib.rs#L98
1210-
fn round_ties_even(x: f64) -> f64 {
1211-
let i = x as i64;
1212-
let f = (x - i as f64).abs();
1213-
if f == 0.5 {
1214-
if i & 1 == 1 {
1215-
// -1.5, 1.5, 3.5, ...
1216-
(x.abs() + 0.5).copysign(x)
1217-
} else {
1218-
(x.abs() - 0.5).copysign(x)
1219-
}
1220-
} else {
1221-
x.round()
1222-
}
1223-
}
1224-
component_wise_float(self, span, [arg], |e| match e {
1225-
Float::Abstract([e]) => Ok(Float::Abstract([round_ties_even(e)])),
1226-
Float::F32([e]) => Ok(Float::F32([(round_ties_even(e as f64) as f32)])),
1227-
})
1204+
component_wise_float!(self, span, [arg], |e| { Ok([e.round_ties_even()]) })
12281205
}
12291206
crate::MathFunction::Fract => {
12301207
component_wise_float!(self, span, [arg], |e| {

0 commit comments

Comments
 (0)