2015-06-29 12:37 AM
Hello Sirs,
Doesanybody use IEEE 754 format to represent float numbers?I need toconvert values to this standard format, and I was wondering if someone of youhas already done it with any STM32F.
I�d bepleased if you can share a sample code showing conversion.
For exmaple:3.141516
�
0x40490e99
http://www.h-schmidt.net/FloatConverter/IEEE754.html
How to do it with C code?
thank youin advance!
Bestregards.
Jai
#ieee-754-float-numbers2015-06-29 02:44 AM
I'm sure your compiler is supporting the IEEE 754 standard, just use the float type and tell your compiler to use software floating point ABI (if your microcontroller has hardware FPU then use hardware floating point ABI for accelerated calculations). If you are using GCC then see the
-mfloat-abi options
https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
. These are the options of GCC that I'm using for STM32F4 with FPU to use hardware FPU: arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 Then you should also initialize the FPU of the MCU in your code before using it.Read more about hardware FPUhttp://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00047pdf
.2015-06-29 01:07 PM
Look for source code of the atof() or atod() functions, which can be used directly, or indirectly through sscanf(), etc.
If you just want the 32-bit hex version, learn how to use casting of pointers.void floattohex(float f){ printf(''%08X\n'', *((unsigned long *)&f) );}2015-06-29 01:31 PM
Could you do the conversion yourself if it was an integer? Do you have any familiarity with other fixed or floating point representations of data? Exponents?
Trying to understand where you're knowledge breaks down.A full-up implementation of atod() is very complex. If you have a smaller numeric ranges, and want to understand the mechanics of the mantissa/exponent representation, you could ignore the decimal point, convert to an integer, counting the digits after the point, and multiply the answer via powf(), or divide using a power-of-ten accumulator.