MadsKirkFoged / EngineeringUnits

Working with units made easy with automatic unit-check and converting between units
MIT License
41 stars 10 forks source link

Adding IsNaN method #42

Closed mschmitz2 closed 7 months ago

mschmitz2 commented 7 months ago
Mass m = Mass.NaN;

Can now do

bool test = m.IsNaN();

instead of

bool test = double.IsNaN(m.SI);
MadsKirkFoged commented 7 months ago

Looks good! Good job making small, easy to read commits! and for remembering to create/change unit tests.

MadsKirkFoged commented 7 months ago

You could upgrade you solution with this if you want.

    public static bool IsNaN(this BaseUnit a)
    {
        if (a is null)
            return false;

        //return double.IsNaN(a.Value); // TODO: avoid using deprecated .Value here
        //return double.IsNaN(a.GetValueAsDouble(UnitSystemExtensions.UnitsystemForDouble));
        //return double.IsNaN(a.As(UnitSystemExtensions.UnitsystemForDouble));
        return a.NEWValue.IsNaN;
    }
mschmitz2 commented 7 months ago

Oh, right, I had overlooked that. Makes way more sense