Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

minimum of float in c++

I want to get a minimum of float without using std::numeric_limits<T>::lowest() [c++11]

so I intend to do the following. -std::numeric_limits<T>::max() can I use it like this?

like image 766
colIn Avatar asked Dec 05 '25 20:12

colIn


1 Answers

Yes you can use -std::numeric_limits<T>::max(). To make sure it is safe in the future, add a unit test to your project to confirm that -std::numeric_limits<T>::max() is the same as std::numeric_limits<T>::lowest() for float and double (or whatever floating point types you are using).

If your T is actually some user- or library-defined type, it may not be safe to do this...but then your unit tests would flag it.

like image 200
John Zwinck Avatar answered Dec 08 '25 10:12

John Zwinck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!