Skip to content

Warn if TActual is object for Numeric Comparison #837

@manfred-brands

Description

@manfred-brands

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));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions