Skip to content

Some numeric_limits and numeric helper functions were missing#331

Merged
nholthaus merged 2 commits intonholthaus:masterfrom
siposcsaba89:master
Dec 9, 2024
Merged

Some numeric_limits and numeric helper functions were missing#331
nholthaus merged 2 commits intonholthaus:masterfrom
siposcsaba89:master

Conversation

@siposcsaba89
Copy link
Contributor

Extended std::numeric_limits class with some functions needed to use it with yaml-cpp.

Copy link

@BenFrantzDale BenFrantzDale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping for this! I have to jump through hoops to get inf.

A few comments. Also, you should probably add tests in https://github.com/nholthaus/units/blob/master/unitTests/main.cpp

Comment on lines +4857 to +4860
static constexpr units::unit_t<Units, T, NonLinearScale> epsilon()
{
return units::unit_t<Units, T, NonLinearScale>(std::numeric_limits<T>::epsilon());
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is epsilon near 1.0, I feel like it's not unit-invariant the same way lowest() is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, it depends on the underlying type, or I don't understand something,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought here is I can’t think of a case where you’d want epsilon that wasn’t better served by multiplying by std::numeric_limits<double>::epsilon(). Epsilon is the smallest increment you add to 1.0 to get a different number, but with units, 1.0 what? I can find the epsilon WRT 1.0_mm by multiplying by double-epsilon, but I can’t think of a use case in which the number isn’t magic. Does that make sense?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like if I change D between meters and millimeters then 1.0_mm + std::numeric_limits<D>::epsilon() would change truthiness, I think.

return std::signbit(x());
}

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, added with the new commit.

include/units.h Outdated

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is missing too, included with the new commit

@siposcsaba89
Copy link
Contributor Author

I was hoping for this! I have to jump through hoops to get inf.

A few comments. Also, you should probably add tests in https://github.com/nholthaus/units/blob/master/unitTests/main.cpp

Also added some unit tests for limits. Can you check them? Maybe you have some other tests in mind.

@nholthaus
Copy link
Owner

great PR guys thanks!!

@nholthaus nholthaus merged commit 17b3274 into nholthaus:master Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments