Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c#

In C# I have (saw with Visual Studio watch tool) :

float.MinValue = -3.40282347E+38

And in C++ :

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

Why are the values not the same? And how can I get -3.40282347E+38 (C# value) in C++ ?

like image 952
A.Pissicat Avatar asked Oct 26 '17 12:10

A.Pissicat


2 Answers

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

Returns the lowest finite value representable by the numeric type T, that is, a finite value x such that there is no other finite value y where y < x. This is different from std::numeric_limits<T>::min() for floating-point types.

like image 118
Jodocus Avatar answered Oct 13 '22 18:10

Jodocus


The two values you're showing are two different things. The first one, -3.40282347E+38, is a large negative value; it's the smallest value that can be represented as a float. The second one, 1.17549435e-038, is a tiny non-negative value; it's the smallest number greater than 0 that can be represented.

like image 20
Pete Becker Avatar answered Oct 13 '22 19:10

Pete Becker