简体   繁体   English

为什么float.min在C ++和C#之间有所不同?

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

In C# I have (saw with Visual Studio watch tool) : 在C#中我有(用Visual Studio监视工具看到):

float.MinValue = -3.40282347E+38

And in C++ : 在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++ ? 如何在C ++中获得-3.40282347E+38 (C#值)?

You are looking for numeric_limits::lowest . 您正在寻找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. 返回由数字类型T表示的最低有限值,即有限值x,使得在y <x时不存在其他有限值y。 This is different from std::numeric_limits<T>::min() for floating-point types. 这与浮点类型的std::numeric_limits<T>::min()不同。

The two values you're showing are two different things. 您展示的两个值是两个不同的东西。 The first one, -3.40282347E+38, is a large negative value; 第一个,-3.40282347E + 38,是一个很大的负值 ; it's the smallest value that can be represented as a float. 它是可以表示为浮点数的最小值。 The second one, 1.17549435e-038, is a tiny non-negative value; 第二个,1.17549435e-038,是一个微小的非负值 ; it's the smallest number greater than 0 that can be represented. 它是可以表示的大于0的最小数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM