浮动小于FLT_MIN。为什么FLT_TRUE_MIN? [英] floats smaller than FLT_MIN. why FLT_TRUE_MIN?
问题描述
#include< stdio.h>
和第二个范围,精度从
#include< stdlib.h>
#include< float.h>
int main(int argc,const char * argv [])
{
float underflow = FLT_MIN * 0.0000004;
$ b printf(Float min是%f或%e.\\\
下流是%f或%e \ nMin float exp是%d.\\\
,FLT_MIN,FLT_MIN,下溢,下溢,FLT_MIN_10_EXP);
返回0;
$ p $浮动最小值是0.000000或1.175494e -38。
下溢是0.000000或4.203895e-45
最小浮动exp是-37。
- 有没有更有效的方法来证明数据类型的限制?
- 为什么FLT_MIN实际上不是最小的浮点值?我应该使用其他常量吗?输入之前的问题后,我发现FLT_TRUE_MIN。这个数字是什么? 2个可能性使得低于最低限度:
float
范围:
典型的float
数字有2个范围:从FLT_MAX
下降到<$ c $的全精度(正常范围) c> FLT_MINFLT_MIN
下降到FLT_TRUE_MIN
。这个第二个范围,称为subnormal通常提供大约10 ^ -7更多的范围。
$ b
FLT_TRUE_MIN
是最小正浮点数
$ FLT_MIN 是最小正规浮点数点的数量
FLT_MIN_10_EXP
是最小的负整数,使得10次上升到该范围内
C11dr§5.2.4.2.2
<一般而言0<数学运算如下:
double
。
printf()
float 传递给double
。 C允许代码进行优化,使得传递给printf()
的值可以是<$ c $的double
乘积c> FLT_MIN * 0.0000004 。float underflow = FLT_MIN * 0.0000004;
printf(%e \\\
,下溢);
如果输出为
4.701976e-45
而不是4.203895e-45
,情况就是这样。
请注意subnormal。对于低于正常(或反常规)数字的令人信服的理由在于以下问题。
float a, b;
... //以某种方式设置a和b。
//是否等于2?
if(a == b)foo();
if((a - b)== 0)foo();
如果没有低于正常的数字,那么在
FLT_MIN
将会有一个非零的数学差异,远远低于FLT_MIN
,结果会变成0.0
。
$ b $ p如果子数目不正确,每对不同的
float
s的区别可以用< $ C> 0.0 。 **
**除
+0.0,-0.0
外。签名的零有自己的特点。In an attempt to see what would happen in the case of a float underflow I found that I could make float numbers much smaller than FLT_MIN. I'm using xcode 5.1 on OS 10.9. The language dialect is gnu99.
#include <stdio.h> #include <stdlib.h> #include <float.h> int main(int argc, const char * argv[]) { float underflow = FLT_MIN * 0.0000004; printf("Float min is %f or %e.\nUnderflow is %f or %e\nMin float exp is %d.\n", FLT_MIN, FLT_MIN, underflow, underflow, FLT_MIN_10_EXP); return 0; }
Prints:
Float min is 0.000000 or 1.175494e-38.
Underflow is 0.000000 or 4.203895e-45
Min float exp is -37.
- Is there a more effective method of demonstrating the limits of data types?
- Why is FLT_MIN not actually the smallest float value? Are there other constants that I'm supposed to be using? After typing the previous question I found FLT_TRUE_MIN. What is this number?
解决方案2 possibilities to get "below minimum":
float
range:Typical
float
numbers have 2 ranges: full precision (normal range) fromFLT_MAX
down toFLT_MIN
and a 2nd range with reducing precision fromFLT_MIN
down toFLT_TRUE_MIN
. This 2nd range, called "subnormal" typically provides about 10^-7 more range.
FLT_TRUE_MIN
is the "minimum positive floating-point number"
FLT_MIN
is the "minimum normalized positive floating-point number"
FLT_MIN_10_EXP
is the "minimum negative integer such that 10 raised to that power is in the range of normalized floating-point numbers"C11dr §5.2.4.2.2
In general
0 < FLT_TRUE_MIN <= FLT_MIN <= 10^FLT_MIN_10_EXP <= 10^-37
Math performed as
double
.
printf()
coverts eachfloat
passed to it to adouble
. C allows code to optimize such that the value passed toprintf()
may be thedouble
product ofFLT_MIN * 0.0000004
.float underflow = FLT_MIN * 0.0000004; printf("%e\n", underflow);
Had the output been
4.701976e-45
rather than4.203895e-45
, this would have been the case.
Note on "subnormal". A compelling reason for subnormal (or denormal) numbers lies in the following problem.
float a,b; ... // somehow a and b are set. // Are the 2 below equivalent? if (a == b) foo(); if ((a - b) == 0) foo();
Without subnormal numbers, 2 nearly the same value numbers near
FLT_MIN
would have a non-zero mathematical difference much belowFLT_MIN
and the result would round to0.0
.With subnormal numbers, the difference of every pair of different
float
s is representable by something other than0.0
. **** Except
+0.0, -0.0
. Signed zeros have their own peculiarities.这篇关于浮动小于FLT_MIN。为什么FLT_TRUE_MIN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!