Why is float.min different between C ++ and C #?

In C #, I have (seen with a Visual Studio viewer):

float.MinValue = -3.40282347E+38 

And in C ++:

 std::numeric_limits<float>::min() = 1.17549435e-038 

Why don't the values ​​match? And how can I get -3.40282347E+38 (C # value) in C ++?

+5
source share
2 answers

You are looking for numeric_limits::lowest . As indicated there:

Returns the smallest final value represented by the numeric type T, i.e. the final value of x is such that there is no other final value of y where y <x. This is different from std::numeric_limits<T>::min() for floating point.

+17
source

The two meanings that you show are two different things. The first, -3.40282347E + 38, is a large negative value ; this is the smallest value that can be represented as a float. The second, 1.17549435e-038, is a tiny non-negative value ; this is the smallest number greater than 0 that can be represented.

+4
source

Source: https://habr.com/ru/post/1272914/


All Articles