long int to float

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
2,190件の閲覧回数
juancarlossuare
Contributor III

Hello.

¿How to convert from long int to float?

ラベル(1)
0 件の賞賛
返信
1 解決策
1,927件の閲覧回数
juancarlossuare
Contributor III

We can use type cast to convert long int to float. For example:

volatile long int l_val=5;

volatile float f_result,f_val=1.23;

f_result=(float)l_val/f_val;

In above code " l_val " computes as float.


元の投稿で解決策を見る

0 件の賞賛
返信
5 返答(返信)
1,927件の閲覧回数
Monica
Senior Contributor III

Juan, I invite you to mark the best answer as correct, this way other people experiencing the same problem can identify the solution.

If the answers here have not helped, let us know!

Regards!

0 件の賞賛
返信
1,927件の閲覧回数
juancarlossuare
Contributor III

Hello Monica.

This answer was given in a service request of freescale.

We can use type cast to convert long int to float. For example:

volatile long int l_val=5;

volatile float f_result,f_val=1.23;

f_result=(float)l_val/f_val;

In above code " l_val " computes as float.


0 件の賞賛
返信
1,928件の閲覧回数
juancarlossuare
Contributor III

We can use type cast to convert long int to float. For example:

volatile long int l_val=5;

volatile float f_result,f_val=1.23;

f_result=(float)l_val/f_val;

In above code " l_val " computes as float.


0 件の賞賛
返信
1,927件の閲覧回数
bigmac
Specialist III

Hello,

You might want to see if you get approximately the correct value when I_val is initialised with a value that exceeds the 16-bit  numeric range, e.g. long int I_val = 123456L;  Of course, the conversion to float will usually result in some loss of precision, maybe with accuracy limited to about 5 digits.

Regards,

Mac


0 件の賞賛
返信
1,927件の閲覧回数
kef
Specialist I

Mac,

conversion from int to float is exact provided integer can fit FP mantissa. For single precision float, with its 24bit mantissa, no precision is lost converting long int's in the range -16777215 to +16777215.

0 件の賞賛
返信