Comments (4)
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.
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.
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.
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)
- Custom units incompatible with decimal format? HOT 3
- ToAutoUnitString HOT 3
- Wrong Plural for MeterPerMinute Speed Units Names HOT 1
- Include yard-based density units HOT 4
- Automatically retrieve Type based on Unit HOT 4
- New Unit - Grade (Slope) HOT 12
- Add Molality units HOT 1
- Insulin concentration HOT 1
- Units of time on Mars HOT 3
- Brackets missing when there are multiple denominators in units string HOT 1
- Bad conversion from base unit 0.1 (example: deciliter to liter) for decimal number. HOT 1
- Protobuf-Net support not working because of DataMember order 0 HOT 1
- Accuracy Issue when converting from CubicMeters to CubicInches HOT 2
- Possible issues with the IComparable interface and associated operators HOT 8
- Quantity.Equals(Quantity other, Quantity tolerance) gives false negative due to floating-point arithmetic HOT 1
- Add type safety and improve type inference in `UnitsMath.cs` HOT 6
- v4.117.0 breaks quantity comparison between different units HOT 3
- Support Cross-Technologies DTO & API Specifications
- NuGets license: MIT instead of MIT-0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unitsnet.