浮点减法与FLT_MAX错误 [英] Floating point subtraction with FLT_MAX error
问题描述
只是一个小小的程序。无法弄清楚我做错了什么。
#include< stdio.h>
#include< limits.h>
#include< float.h>
int main()
{
double max = FLT_MAX;
double sub = 16703.627681;
double result = max - sub;
printf( %f - %f =%f \ n,最大,次,结果);
返回0;
}
输出:
340282346638528859811704183484516925440.000000 - 16703.627681 =
340282346638528859811704183484516925440.000000
我们非常感谢任何帮助。
谢谢
Just a small little program. Can not figure out what am I doing wrong.
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main()
{
double max = FLT_MAX;
double sub = 16703.627681;
double result = max - sub;
printf("%f - %f = %f\n", max, sub, result);
return 0;
}
Output:
340282346638528859811704183484516925440.000000 - 16703.627681 =
340282346638528859811704183484516925440.000000
Any help would be highly appreciated.
Thanks
推荐答案
10月25日晚上7:56,spooler ... @ gmail。 com写道:
On Oct 25, 7:56 pm, spooler...@gmail.com wrote:
只是一个小程序。无法弄清楚我做错了什么。
#include< stdio.h>
#include< limits.h>
#include< float.h>
int main()
{
double max = FLT_MAX;
double sub = 16703.627681;
double result = max - sub;
printf( %f - %f =%f \ n,max,sub,result);
返回0;
}
输出:
340282346638528859811704183484516925440.000000 - 16703.627681 =
340282346638528859811704183484516925440.000000
任何帮助都会非常感谢。
谢谢
Just a small little program. Can not figure out what am I doing wrong.
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main()
{
double max = FLT_MAX;
double sub = 16703.627681;
double result = max - sub;
printf("%f - %f = %f\n", max, sub, result);
return 0;
}
Output:
340282346638528859811704183484516925440.000000 - 16703.627681 =
340282346638528859811704183484516925440.000000
Any help would be highly appreciated.
Thanks
看来你正在尝试使用一个打印双倍(%Lf)
浮动(%f)因此您看到的错误。查看下面的链接
了解有关printf()函数及其修饰符的更多信息。
http://www.cplusplus.com/reference/c...io/printf.html
Keith
http://www.doubleblackdesign.com
http://www.doubleblackdesign.com/forums
It appears that you are trying to print a double (%Lf) by using a
float (%f) hence the error you are seeing. Check out the link below
for more info on the printf() function and it''s modifiers.
http://www.cplusplus.com/reference/c...io/printf.html
Keith
http://www.doubleblackdesign.com
http://www.doubleblackdesign.com/forums
10月25日下午5:06,husterk< hust ... @ gmail.comwrote:
On Oct 25, 5:06 pm, husterk <hust...@gmail.comwrote:
10月25日晚上7:56,spooler ... @ gmail.com写道:
On Oct 25, 7:56 pm, spooler...@gmail.com wrote:
只是一个小小程序。无法弄清楚我做错了什么。
Just a small little program. Can not figure out what am I doing wrong.
#include< stdio.h>
#include< limits.h>
#include< float.h>
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main()
{
int main()
{
double max = FLT_MAX;
double sub = 16703.627681;
double max = FLT_MAX;
double sub = 16703.627681;
double result = max - sub;
double result = max - sub;
printf("%f - %f =%f \ n",max,sub,result);
printf("%f - %f = %f\n", max, sub, result);
返回0;
return 0;
}
}
输出:
340282346638528859811704183484516925440.000000 - 16703.627681 =
340282346638528859811704183484516925440.000000
Output:
340282346638528859811704183484516925440.000000 - 16703.627681 =
340282346638528859811704183484516925440.000000
我们非常感谢任何帮助。
Any help would be highly appreciated.
谢谢
Thanks
看来您正在尝试打印双倍(%Lf )使用
浮点数(%f)因此出现错误。查看下面的链接
了解有关printf()函数及其修饰符的更多信息。
http://www.cplusplus.com/reference/c...io/printf.html
Keithhttp://www.doubleblackdesign.comhttp://www.doubleblackdesign.com/forums
It appears that you are trying to print a double (%Lf) by using a
float (%f) hence the error you are seeing. Check out the link below
for more info on the printf() function and it''s modifiers.
http://www.cplusplus.com/reference/c...io/printf.html
Keithhttp://www.doubleblackdesign.comhttp://www.doubleblackdesign.com/forums
已经尝试过了。相同的结果。
%lf
340282346638528859811704183484516925440.000000 - 16703.627681 =
340282346638528859811704183484516925440.000000
%LF(不是长双吗?)
340282346638528859811704183484516925440.000000 - 16703.627681 =
0.000000
感谢您的回复。
另外据我所知,printf并不关心它是%f还是%lf因为
一切都变成了双倍,它是scanf抱怨的。如果我错了,请纠正我。
Tried that already. Same results.
%lf
340282346638528859811704183484516925440.000000 - 16703.627681 =
340282346638528859811704183484516925440.000000
%LF (Isn''t it for long double?)
340282346638528859811704183484516925440.000000 - 16703.627681 =
0.000000
Thanks for the reply.
Also as far as I know printf does not care if it is %f or %lf as
everything goes as double, it is scanf which complains. Correct me if
I am wrong.
sp ******** @ gmail.com 写道:
sp********@gmail.com wrote:
只是一个小小的程序。无法弄清楚我做错了什么。
#include< stdio.h>
#include< limits.h>
#include< float.h>
int main()
{
double max = FLT_MAX;
double sub = 16703.627681;
double result = max - sub;
printf( %f - %f =%f \ n,最大,次,结果);
返回0;
}
输出:
340282346638528859811704183484516925440.000000 - 16703.627681 =
340282346638528859811704183484516925440.000000
Just a small little program. Can not figure out what am I doing wrong.
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main()
{
double max = FLT_MAX;
double sub = 16703.627681;
double result = max - sub;
printf("%f - %f = %f\n", max, sub, result);
return 0;
}
Output:
340282346638528859811704183484516925440.000000 - 16703.627681 =
340282346638528859811704183484516925440.000000
如果发生你这样做:
double max = DBL_MAX;
What happens if you do:
double max = DBL_MAX;
这篇关于浮点减法与FLT_MAX错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!