Giter Site home page Giter Site logo

Comments (4)

tmilnthorp avatar tmilnthorp commented on May 28, 2024

Indeed the conversion to C (-273.15) results in a negative absolute tolerance.

That said, it is working as expected by the current design. We could add an overload with TemperatureDelta, but I am not sure we should even maintain that unit long-term (@angularsen?).

In the meantime, you can use

var equals = t1.Equals(t2, tolerance: Temperature.FromDegreesCelsius(0));

or just

var equals = t1.Equals(t2);

from unitsnet.

park-jasper avatar park-jasper commented on May 28, 2024

Hi Tristan, thank you for the swift reply.

I must disagree with your suggested alternatives. passing Temperature.FromDegreesCelsius(0) would result in a wrong result if t1 was specified using e.g. kelvin. the caller of that method should not need to know which unit t1 has and have to specify the tolerance accordingly.
The second approach using .Equals without the tolerance parameter is marked obsolete because it cannot compare t1 and t2 properly if they have been defined using different units, and it should not be the responsibility of the caller of .Equals to ensure that both have the same unit.

from unitsnet.

tmilnthorp avatar tmilnthorp commented on May 28, 2024

Fair point on the first one.

I have been away from the code for a bit, and just checked Equals(). It used to do a conversion before doing "strict" equality, but now we are "ultra-strict" in that we do no conversion first and check both the value and unit exactly. Whether we should or shouldn't convert first up for debate, but you are correct that it now will not work for you. Sorry.

It seems without modifications to UnitsNet your only option would be

var equals = t1.Equals(t2.ToUnit(t1.Unit));

Which is not exactly elegant :)

from unitsnet.

park-jasper avatar park-jasper commented on May 28, 2024

The suggested approach would work for me. But I am also looking to prevent the pitfall of someone else using the recommended .Equals method and then getting the wrong result. In my case the ArgumentOutOfRangeException was hard to miss, but in another case one may be comparing temperatures and it returning true, when it should not.

I can see that this is a quirk that is unique to Temperature and TemperatureDelta where they do not have the same conversion, and thus is a problem that requires some specialized logic for just those cases. But I also believe that it should not stay the way it is because the method does not return the right results.

I was going to do a PR with a suggestion for a fix as well, but then realised the problem is a bit bigger than just changing a method's parameter from Temperature to TemperatureUnit and adding a bit of conversion logic.

from unitsnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.