双倍和/或浮点数乘法的问题 [英] Problems with multiplications of doubles and/or floats
问题描述
你好,
我试图将双倍乘以花车(实际上我现在尝试了每一个
可能的组合)并且它永远不会起作用(好吧) ,它做了一些事情
但它总是错的)。我不知道它是什么以及在哪里寻找
帮助,也许有些人知道吗?
double = float * double; (或它的每种可能的组合)。一个例子:
0.3 * 0.7会导致1.7(有更多的数字)。有人知道吗?
如果我改变变量的类型我认为结果保持不变
(但我不是100%肯定)...
Jens
Hi there,
I am trying to multiply doubles with floats (actually I tried every
possible combination by now) and it never works (well, it does something
but it is always wrong). I have no idea what it is and where to look for
help, maybe some of you know?
double=float*double; (or every possible combination of it). An example:
0.3 * 0.7 would result in 1.7 (with lots more digits). Anyone any idea?
If I change the types of the variables I think the result stays the same
(but I am not 100% sure)...
Jens
推荐答案
对不起,我忘记了:
Linux(Debian)和gcc3.3
Jens
Sorry, I forgot:
Linux (Debian) and gcc3.3
Jens
JK Becker写道:
J.K. Becker wrote:
你好,
我试图将双倍乘以浮点数(实际上我现在尝试了每一个可能的组合)并且它永远不会起作用(好吧) ,它做了一些事情
但它总是错误的)。我不知道它是什么,在哪里寻找帮助,也许有些人知道?
double = float * double; (或它的每种可能的组合)。一个例子:
0.3 * 0.7会导致1.7(有更多的数字)。任何人都有任何想法吗?
如果我改变变量的类型我认为结果保持不变
(但我不是100%肯定)...
Jens
Hi there,
I am trying to multiply doubles with floats (actually I tried every
possible combination by now) and it never works (well, it does something
but it is always wrong). I have no idea what it is and where to look for
help, maybe some of you know?
double=float*double; (or every possible combination of it). An example:
0.3 * 0.7 would result in 1.7 (with lots more digits). Anyone any idea?
If I change the types of the variables I think the result stays the same
(but I am not 100% sure)...
Jens
我没有得到同样的答案:
TH009MA @ th009ma-shl2-01 / cygdrive / d / temp
I don''t get the same answer:
TH009MA@th009ma-shl2-01 /cygdrive/d/temp
cat junk.c
#include< stdio.h>
#include< stdlib.h>
int main(无效)
{
const double three_tenths = 0.3;
const double seven_tenths = 0.7;
const float f_three_tenths = 0.3;
const float f_seven_tenths = 0.7;
printf(" direct multiplication:0.3 * 0.7 =%f \ n",0.3 * 0.7);
printf(" double * double:%f\ n",three_tenths * seven_tenths);
printf (float * float:%f \ n,f_three_tenths * f_seven_tenths);
printf(" double * float:%f \ n",three_tenths * f_seven_tenths);
printf(" f loat * double:%f \ n",f_three_tenths * seven_tenths);
返回EXIT_SUCCESS;
}
TH009MA @ th009ma-shl2-01 / cygdrive / d / temp
cat junk.c
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
const double three_tenths = 0.3;
const double seven_tenths = 0.7;
const float f_three_tenths = 0.3;
const float f_seven_tenths = 0.7;
printf("direct multiplication: 0.3 * 0.7 = %f\n", 0.3 * 0.7);
printf("double * double: %f\n", three_tenths * seven_tenths);
printf("float * float: %f\n", f_three_tenths * f_seven_tenths);
printf("double * float: %f\n", three_tenths * f_seven_tenths);
printf("float * double: %f\n", f_three_tenths * seven_tenths);
return EXIT_SUCCESS;
}
TH009MA@th009ma-shl2-01 /cygdrive/d/temp
这篇关于双倍和/或浮点数乘法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!