Reputation: 5432
I'm trying to set a simple division in a project, on STM32F10x here what I've done :
say I got a float variable:
float f =0.0;
.............
when I use f
this way :
f = 20/5 ;
the program can't use the value of f
which is the result of the division, I'm using this value in multiple other functions in the Program, but none of them works meaning that I'dont get an error but the program doesn't work .
but when set the value :
f = 4 ;
everything works fine !
any idea why ?
I've used :
f = (float) 20/5 ;
Upvotes: 2
Views: 3025
Reputation: 117330
The compiler treats all floating point numbers without a suffix as double
.
This will blow up on STM32/ARM.
Use a suffix, iow 20.0f
.
The reason your cast works is because the result can be determined at compile time. If not, it will blow up again.
Upvotes: 6