我可以比较,并添加一个浮点数在C整数? [英] Can I compare and add a floating-point number to an integer in C?

查看:178
本文介绍了我可以比较,并添加一个浮点数在C整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以比较浮点数为整数?

Can I compare a floating-point number to an integer?

请问浮动比较整数code?

Will the float compare to integers in code?

float f;     // f has a saved predetermined floating-point value to it  
if (f >=100){__asm__reset...etc}

另外,可能我...

Also, could I...

float f;
int x = 100;
x+=f;

我必须使用浮点值的˚F从姿态参考系统调整位置值获得的 X 控制的PWM信号来纠正的态度。

I have to use the floating point value f received from an attitude reference system to adjust a position value x that controls a PWM signal to correct for attitude.

推荐答案

第一个将正常工作。 100将被转换为float,并且IEE754都可以准确的整数重新present作为花车,高达约2 23

The first one will work fine. 100 will be converted to a float, and IEE754 can represent all integers exactly as floats, up to about 223.

第二个也将工作,但将被转换成整数第一,所以你会失去precision(如果你彩车转成整数是不可避免的)。

The second one will also work but will be converted into an integer first, so you'll lose precision (that's unavoidable if you're turning floats into integers).

这篇关于我可以比较,并添加一个浮点数在C整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆