Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if TActual is object for Numeric Comparison #837

Open
manfred-brands opened this issue Jan 24, 2025 · 0 comments
Open

Warn if TActual is object for Numeric Comparison #837

manfred-brands opened this issue Jan 24, 2025 · 0 comments

Comments

@manfred-brands
Copy link
Member

Given code:

[Test]
public void TestFoatsAndDoubles()
{
    object x = 0.0500000007f;
    Assert.That(x, Is.EqualTo(0.05).Within(0.0000001));
}

This boxes the floating point constant into an object to then do a numeric comparison.
The idea is to remove expensive boxing and subsequent unboxing when not needed.

Fixed code ideally should create:

[Test]
public void TestFoatsAndDoubles()
{
    float x = 0.0500000007f;
    Assert.That(x, Is.EqualTo(0.05).Within(0.0000001));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant