Janitor: Use approx_eq when checking for integer

Use approx_eq when comparing the value.trunc() to value. We want to
allow these values to be calculated, so they might end up slightly off.
This commit is contained in:
Tobias Hunger 2021-07-30 00:13:08 +02:00 committed by Simon Hausmann
parent f1f0182826
commit 85f7c93c87

View file

@ -9,6 +9,8 @@
LICENSE END */
//! Passe that compute the layout constraint
use lyon_path::geom::euclid::approxeq::ApproxEq;
use crate::diagnostics::BuildDiagnostics;
use crate::diagnostics::Spanned;
use crate::expression_tree::*;
@ -502,7 +504,7 @@ fn eval_const_expr(
) -> Option<u16> {
match expression {
Expression::NumberLiteral(v, Unit::None) => {
if *v < 0. || *v > u16::MAX as f64 || v.trunc() != *v {
if *v < 0. || *v > u16::MAX as f64 || !v.trunc().approx_eq(v) {
diag.push_error(format!("'{}' must be a positive integer", name), span);
None
} else {