-3

I have started working with C language recently. I have one simple problem

 Unsigned int a;
 float b;
  a=8000;
 b=(((((float)a)/65535)-1)/0.245);    //  b= ((a/65535)-1)/0.245;
 printf("value:%f \r\n", b);

I don't know what is the problem in the above formula but I am not able to print "b" value. I will get "b value as negative". how to print "b value"?

4

2 回答 2

1
8000 / 65535         =  0,122072175
0,122072175 - 1      = -0,877927825
-0,877927825 / 0,245 = -3,58337888

如果-3,5833是您获得的值,那么您将获得正确的结果。

于 2012-10-19T12:12:03.600 回答
0

如果您只想要 b 的原始值,则必须这样做

b = fabsf(b);
OR
printf("value:%f \r\n", fabsf(b));

因为对于 a < 65535.0 的所有 a 值,此 b 始终为负

这是假设您包含一个数学库。

于 2012-10-19T12:14:09.637 回答