Remove stray float literal .0 suffixes in lieu of just ending with a point (#4233)

Remove the .0 suffix on floats in lieu of just ending with a point
This commit is contained in:
Keavon Chambers
2026-06-12 19:47:36 -07:00
committed by GitHub
parent 2b8ef42086
commit cde8dd78e6
23 changed files with 125 additions and 125 deletions

View File

@@ -111,8 +111,8 @@ lazy_static! {
map.insert(
"invcot",
Box::new(|values| match values {
[Value::Number(Number::Real(real))] => Some(Value::Number(Number::Real((PI / 2.0 - real).atan()))),
[Value::Number(Number::Complex(complex))] => Some(Value::Number(Number::Complex((Complex::new(PI / 2.0, 0.0) - complex).atan()))),
[Value::Number(Number::Real(real))] => Some(Value::Number(Number::Real((PI / 2. - real).atan()))),
[Value::Number(Number::Complex(complex))] => Some(Value::Number(Number::Complex((Complex::new(PI / 2., 0.) - complex).atan()))),
_ => None,
}),
);

View File

@@ -63,38 +63,38 @@ mod tests {
}
eval_tests! {
test_addition: Value::from_f64(7.0) => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(3.0))),
test_addition: Value::from_f64(7.) => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(3.))),
op: BinaryOp::Add,
rhs: Box::new(Node::Lit(Literal::Float(4.0))),
rhs: Box::new(Node::Lit(Literal::Float(4.))),
},
test_subtraction: Value::from_f64(1.0) => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(5.0))),
test_subtraction: Value::from_f64(1.) => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(5.))),
op: BinaryOp::Sub,
rhs: Box::new(Node::Lit(Literal::Float(4.0))),
rhs: Box::new(Node::Lit(Literal::Float(4.))),
},
test_multiplication: Value::from_f64(12.0) => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(3.0))),
test_multiplication: Value::from_f64(12.) => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(3.))),
op: BinaryOp::Mul,
rhs: Box::new(Node::Lit(Literal::Float(4.0))),
rhs: Box::new(Node::Lit(Literal::Float(4.))),
},
test_division: Value::from_f64(2.5) => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(5.0))),
lhs: Box::new(Node::Lit(Literal::Float(5.))),
op: BinaryOp::Div,
rhs: Box::new(Node::Lit(Literal::Float(2.0))),
rhs: Box::new(Node::Lit(Literal::Float(2.))),
},
test_negation: Value::from_f64(-3.0) => Node::UnaryOp {
expr: Box::new(Node::Lit(Literal::Float(3.0))),
test_negation: Value::from_f64(-3.) => Node::UnaryOp {
expr: Box::new(Node::Lit(Literal::Float(3.))),
op: UnaryOp::Neg,
},
test_sqrt: Value::from_f64(2.0) => Node::UnaryOp {
expr: Box::new(Node::Lit(Literal::Float(4.0))),
test_sqrt: Value::from_f64(2.) => Node::UnaryOp {
expr: Box::new(Node::Lit(Literal::Float(4.))),
op: UnaryOp::Sqrt,
},
test_power: Value::from_f64(8.0) => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(2.0))),
test_power: Value::from_f64(8.) => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(2.))),
op: BinaryOp::Pow,
rhs: Box::new(Node::Lit(Literal::Float(3.0))),
rhs: Box::new(Node::Lit(Literal::Float(3.))),
},
}
}

View File

@@ -130,20 +130,20 @@ mod tests {
constant_pi: "pi" => (std::f64::consts::PI, Unit::BASE_UNIT),
constant_e: "e" => (std::f64::consts::E, Unit::BASE_UNIT),
constant_phi: "phi" => (1.61803398875, Unit::BASE_UNIT),
constant_tau: "tau" => (2.0 * std::f64::consts::PI, Unit::BASE_UNIT),
constant_tau: "tau" => (2. * std::f64::consts::PI, Unit::BASE_UNIT),
constant_infinity: "inf" => (f64::INFINITY, Unit::BASE_UNIT),
constant_infinity_symbol: "" => (f64::INFINITY, Unit::BASE_UNIT),
multiply_pi: "2 * pi" => (2.0 * std::f64::consts::PI, Unit::BASE_UNIT),
add_e_constant: "e + 1" => (std::f64::consts::E + 1.0, Unit::BASE_UNIT),
multiply_phi_constant: "phi * 2" => (1.61803398875 * 2.0, Unit::BASE_UNIT),
exponent_tau: "2^tau" => (2f64.powf(2.0 * std::f64::consts::PI), Unit::BASE_UNIT),
multiply_pi: "2 * pi" => (2. * std::f64::consts::PI, Unit::BASE_UNIT),
add_e_constant: "e + 1" => (std::f64::consts::E + 1., Unit::BASE_UNIT),
multiply_phi_constant: "phi * 2" => (1.61803398875 * 2., Unit::BASE_UNIT),
exponent_tau: "2^tau" => (2f64.powf(2. * std::f64::consts::PI), Unit::BASE_UNIT),
infinity_subtract_large_number: "inf - 1000" => (f64::INFINITY, Unit::BASE_UNIT),
// Trigonometric functions
trig_sin_pi: "sin(pi)" => (0.0, Unit::BASE_UNIT),
trig_cos_zero: "cos(0)" => (1.0, Unit::BASE_UNIT),
trig_tan_pi_div_four: "tan(pi/4)" => (1.0, Unit::BASE_UNIT),
trig_sin_tau: "sin(tau)" => (0.0, Unit::BASE_UNIT),
trig_cos_tau_div_two: "cos(tau/2)" => (-1.0, Unit::BASE_UNIT),
trig_sin_pi: "sin(pi)" => (0., Unit::BASE_UNIT),
trig_cos_zero: "cos(0)" => (1., Unit::BASE_UNIT),
trig_tan_pi_div_four: "tan(pi/4)" => (1., Unit::BASE_UNIT),
trig_sin_tau: "sin(tau)" => (0., Unit::BASE_UNIT),
trig_cos_tau_div_two: "cos(tau/2)" => (-1., Unit::BASE_UNIT),
}
}

View File

@@ -68,7 +68,7 @@ impl NodeMetadata {
}
fn parse_unit(pairs: Pairs<Rule>) -> Result<(Unit, f64), ParseError> {
let mut scale = 1.0;
let mut scale = 1.;
let mut length = 0;
let mut mass = 0;
let mut time = 0;
@@ -102,9 +102,9 @@ fn parse_unit(pairs: Pairs<Rule>) -> Result<(Unit, f64), ParseError> {
fn parse_const(pair: Pair<Rule>) -> Literal {
match pair.as_rule() {
Rule::infinity => Literal::Float(f64::INFINITY),
Rule::imaginary_unit => Literal::Complex(Complex::new(0.0, 1.0)),
Rule::imaginary_unit => Literal::Complex(Complex::new(0., 1.)),
Rule::pi => Literal::Float(std::f64::consts::PI),
Rule::tau => Literal::Float(2.0 * std::f64::consts::PI),
Rule::tau => Literal::Float(2. * std::f64::consts::PI),
Rule::euler_number => Literal::Float(std::f64::consts::E),
Rule::golden_ratio => Literal::Float(1.61803398875),
_ => unreachable!("Unexpected constant: {:?}", pair),
@@ -327,52 +327,52 @@ mod tests {
}
test_parser! {
test_parse_int_literal: "42" => Node::Lit(Literal::Float(42.0)),
test_parse_int_literal: "42" => Node::Lit(Literal::Float(42.)),
test_parse_float_literal: "3.14" => Node::Lit(Literal::Float(#[allow(clippy::approx_constant)] 3.14)),
test_parse_ident: "x" => Node::Var("x".to_string()),
test_parse_unary_neg: "-42" => Node::UnaryOp {
expr: Box::new(Node::Lit(Literal::Float(42.0))),
expr: Box::new(Node::Lit(Literal::Float(42.))),
op: UnaryOp::Neg,
},
test_parse_binary_add: "1 + 2" => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(1.0))),
lhs: Box::new(Node::Lit(Literal::Float(1.))),
op: BinaryOp::Add,
rhs: Box::new(Node::Lit(Literal::Float(2.0))),
rhs: Box::new(Node::Lit(Literal::Float(2.))),
},
test_parse_binary_mul: "3 * 4" => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(3.0))),
lhs: Box::new(Node::Lit(Literal::Float(3.))),
op: BinaryOp::Mul,
rhs: Box::new(Node::Lit(Literal::Float(4.0))),
rhs: Box::new(Node::Lit(Literal::Float(4.))),
},
test_parse_binary_pow: "2 ^ 3" => Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(2.0))),
lhs: Box::new(Node::Lit(Literal::Float(2.))),
op: BinaryOp::Pow,
rhs: Box::new(Node::Lit(Literal::Float(3.0))),
rhs: Box::new(Node::Lit(Literal::Float(3.))),
},
test_parse_unary_sqrt: "sqrt(16)" => Node::UnaryOp {
expr: Box::new(Node::Lit(Literal::Float(16.0))),
expr: Box::new(Node::Lit(Literal::Float(16.))),
op: UnaryOp::Sqrt,
},
test_parse_sqr_ident: "sqr(16)" => Node::FnCall {
name:"sqr".to_string(),
expr: vec![Node::Lit(Literal::Float(16.0))]
expr: vec![Node::Lit(Literal::Float(16.))]
},
test_parse_complex_expr: "(1 + 2) 3 - 4 ^ 2" => Node::BinOp {
lhs: Box::new(Node::BinOp {
lhs: Box::new(Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(1.0))),
lhs: Box::new(Node::Lit(Literal::Float(1.))),
op: BinaryOp::Add,
rhs: Box::new(Node::Lit(Literal::Float(2.0))),
rhs: Box::new(Node::Lit(Literal::Float(2.))),
}),
op: BinaryOp::Mul,
rhs: Box::new(Node::Lit(Literal::Float(3.0))),
rhs: Box::new(Node::Lit(Literal::Float(3.))),
}),
op: BinaryOp::Sub,
rhs: Box::new(Node::BinOp {
lhs: Box::new(Node::Lit(Literal::Float(4.0))),
lhs: Box::new(Node::Lit(Literal::Float(4.))),
op: BinaryOp::Pow,
rhs: Box::new(Node::Lit(Literal::Float(2.0))),
rhs: Box::new(Node::Lit(Literal::Float(2.))),
}),
}
}

View File

@@ -77,7 +77,7 @@ impl Number {
}
(Number::Real(lhs), Number::Complex(rhs)) => {
let lhs_complex = Complex::new(lhs, 0.0);
let lhs_complex = Complex::new(lhs, 0.);
let result = match op {
BinaryOp::Add => lhs_complex + rhs,
BinaryOp::Sub => lhs_complex - rhs,
@@ -89,7 +89,7 @@ impl Number {
}
(Number::Complex(lhs), Number::Real(rhs)) => {
let rhs_complex = Complex::new(rhs, 0.0);
let rhs_complex = Complex::new(rhs, 0.);
let result = match op {
BinaryOp::Add => lhs + rhs_complex,
BinaryOp::Sub => lhs - rhs_complex,