2024-02-06 03:04 AM
Hi guys,
I really need your help.
I'm trying to divide two numbers.. But the result is still 0. Analyzind the disassembling the commands are not those of FPU unit. I enable the FPU in the Properties/MCU Setting.
Here the simple code:
uint32_t A = __HAL_TIM_GET_CLOCKDIVISION(&htim3)+1; // result is 1
uint32_t B = HAL_RCC_GetPCLK2Freq(); // result is 84000000
float D = A/B; // result is 0
double E = A / B; // result is 0
long double F = A / B; // result is 0
double G = 1 / 5; // result is 0
uint32_t H = 10/3; // result is 3
double I = 10/3; // result is 3
Any ideas
Thanks
Solved! Go to Solution.
2024-02-06 03:16 AM - edited 2024-02-06 03:17 AM
Hi,
You have to learn about C , not the cpu is the problem here.
If you want float, you have to use float - or "tell" the compiler about your desire : casting .
+ double is not calculated in hardware, on F401 is just (single) float unit.
try :
float D = (float) A/B;
float D = (float) A/ (float) B;
read...ie:
https://www.tutorialspoint.com/cprogramming/c_type_casting.htm
2024-02-06 03:16 AM - edited 2024-02-06 03:17 AM
Hi,
You have to learn about C , not the cpu is the problem here.
If you want float, you have to use float - or "tell" the compiler about your desire : casting .
+ double is not calculated in hardware, on F401 is just (single) float unit.
try :
float D = (float) A/B;
float D = (float) A/ (float) B;
read...ie:
https://www.tutorialspoint.com/cprogramming/c_type_casting.htm
2024-02-06 04:46 AM
Use this button to properly post source code:
To get that extra row of icons, press this button:
2024-02-06 08:04 AM
Thanks