gul-cpp / gul14

General Utility Library for C++14
https://gul14.info/
GNU Lesser General Public License v2.1
2 stars 1 forks source link

num_util: within_orders() detects 0.0 == 0.0 #18

Closed Finii closed 1 year ago

Finii commented 2 years ago

[why] gul14::within_orders(0.0, 0.0, 5) is false. Instinctively one might expect it to be true, as both inputs are strictly equal.

[how] Check for equality first, then additionally add some lenience.

Fixes: #17

Finii commented 2 years ago

Alternative implementation, which uses ULPs.

In fact we could have used return difference <= limit; BUT that breaks with special floating point values. So it's either the PR version, or this:

bool within_orders(const NumT a, const NumT b, const OrderT orders) noexcept(false) {
    // std::pow() is not noexcept, which might or might not be true
    auto difference = gul14::abs(a - b);
    auto maximum = std::max(gul14::abs(a), gul14::abs(b));
    auto limit = static_cast<NumT>(maximum / std::pow(static_cast<std::decay_t<NumT>>(10.0), orders));
    auto ulp = std::numeric_limits<NumT>::min();
    return difference < std::max(limit, ulp);
}
alt-graph commented 1 year ago

Before merging, maybe we should also bump the version number?

Finii commented 1 year ago

Increased version number and added git tag (this will work if we fast-forward merge) (hopefully ;-)

Finii commented 1 year ago

Obviously 'dismiss' is not the correct button :grimacing:

Finii commented 1 year ago

Before merging, maybe we should also bump the version number?

Hmm, there is no Doocs release between 2.7 and now, so maybe keep 2.7?

image

Finii commented 1 year ago

Ah, more appropriate would be v2.7.1 which keeps the API version at 2.7... changing

Finii commented 1 year ago

image

Finii commented 1 year ago

Hmm, I do not know what Github is doing, but even a ff merge changes the commit hashes, so the tag needs to be adapted:

image

Sigh ...

git tag -d v2.7.1
git push github --delete v2.7.1
git pull github main
git tag -m v2.7.1 v2.7.1
git push github --tags
Finii commented 1 year ago

@alt-graph Is the mirroring automatic, or shall I push to gitlab? Not that Tim builds with the old lib :grimacing:

Finii commented 1 year ago

Mirroring is claimed but not set up??

image

Finii commented 1 year ago

Did it just manually ... any reason this is not automated?

image

alt-graph commented 1 year ago

Did it just manually ... any reason this is not automated?

image

We don't have the paid version of Gitlab, so we cannot automate it from there. We could do it from Github, I guess.