Giter Site home page Giter Site logo

Comments (6)

iliekturtles avatar iliekturtles commented on July 18, 2024

The slight difference in the values is a side effect of normalizing the internal value in meters and floating point imprecision. While PartialEq is implemented, I don't believe it will help in this case.

Floating point accuracy problems are always a hassle! You can see how uom's test code uses approx here:

uom/src/tests/mod.rs

Lines 110 to 140 in 629f385

fn assert_eq(lhs: &Self, rhs: &Self) {
match (lhs.is_nan(), rhs.is_nan()) {
(true, true) => {}
_ => { assert_eq!(lhs, rhs); }
}
}
/// Assert that `lhs` and `rhs` are approximately equal for floating point types or
/// exactly equal for other types.
fn assert_approx_eq(lhs: &Self, rhs: &Self) {
match (lhs.is_nan(), rhs.is_nan()) {
(true, true) => {}
_ => {
assert_ulps_eq!(lhs, rhs, epsilon = EPS_FACTOR * V::epsilon(),
max_ulps = ULPS);
}
}
}
/// Exactly compare `lhs` and `rhs` and return the result.
fn eq(lhs: &Self, rhs: &Self) -> bool {
(lhs.is_nan() && rhs.is_nan())
|| lhs == rhs
}
/// Approximately compare `lhs` and `rhs` for floating point types or exactly compare
/// for other types and return the result.
fn approx_eq(lhs: &Self, rhs: &Self) -> bool {
(lhs.is_nan() && rhs.is_nan())
|| ulps_eq!(lhs, rhs, epsilon = EPS_FACTOR * V::epsilon(), max_ulps = ULPS)
}

from uom.

inferiorhumanorgans avatar inferiorhumanorgans commented on July 18, 2024

Oh, whoops. I was the assert_relative_eq macro. The error was about not implementing the crate's RelativeEq trait.

from uom.

iliekturtles avatar iliekturtles commented on July 18, 2024

Are you proposing implementing approx::RelativeEq inside uom? If we're going to expose approx in uom's public interface I'd want to review other options. In a very brief scan I also found float-cmp and assert_approx_eq. All three seem pretty popular. I'm hesitant to pick a winner, but the orphan rules sort of require doing that.

from uom.

adamreichold avatar adamreichold commented on July 18, 2024

I'm hesitant to pick a winner, but the orphan rules sort of require doing that.

Could you expand on why that is the case? Couldn't uom theoretically implement the traits from all three crates (and in different versions if required)? Also even if uom provides an implementation of only one trait, can't downstream crates still implement the other using newtype wrappers just like they have to do now for any of them? (Which would even allow overriding a provided implementation with the same effort as implementing it in the first place now.)

from uom.

iliekturtles avatar iliekturtles commented on July 18, 2024

I hadn't thought about the opposite and adding multiple implementations. Similar question though, when should the line be drawn on which external crates should be implemented?

from uom.

adamreichold avatar adamreichold commented on July 18, 2024

Similar question though, when should the line be drawn on which external crates should be implemented?

Where you as the maintainer want it to be drawn from an effort versus convenience perspective. Since the basic set of implementable traits is unaffected, the stakes for answering this are not that high, i.e. you can choose one that you like to provide a convenient path for some users while not blocking anything for others.

Of course, just saying no is also a maintainer's prerogative and providing none also does not block anyone from using newtype wrappers. My point basically is that the orphan rules only enforce one thing here: This crate is the only place where we can provide these trait implementations without the additional effort of newtype wrappers.

from uom.

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.