This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

convert from long to float

Hi guys,

I need to convert a 32 bit value(long) to a 32 bit float. Unfortunately there is no itof function in C and wikipedia does not give a simple solution.

Casting simply does not do the conversion correctly, is there a simple way of doing this conversion?

Thanks

Parents
  • C will automatically convert from an integer to a float.

    What do you say "does not do the conversion correctly"?

    Note that a 32-bit float has a larger supported range, but instead has a smaller resolution, i.e. all values in a 32-bit integer will not be possible to represent in a 32-bit float - some integer values will be rounded to another integer value.

Reply
  • C will automatically convert from an integer to a float.

    What do you say "does not do the conversion correctly"?

    Note that a 32-bit float has a larger supported range, but instead has a smaller resolution, i.e. all values in a 32-bit integer will not be possible to represent in a 32-bit float - some integer values will be rounded to another integer value.

Children
No data