How to print the "negative float point number" to show negative value?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to print the "negative float point number" to show negative value?

跳至解决方案
4,759 次查看
felix1
Contributor IV

If I use 

PRINTF("negative float test = %f", -1.234);

to print the negative float point number, I got the positive value from console, like

"negative float test = 1.234000"

Can you help me to fix it to show the real negative value?

p.s. define PRINTF_FLOAT_ENABLE=1

标签 (1)
1 解答
4,662 次查看
kbelete
NXP Employee
NXP Employee

Hi Felix,

Negative floating point values can be printed by opening the Project Properties and defining both “PRINTF_FLOAT_ENABLE” and “PRINTF_ADVANCED_ENABLE” to 1 in the Preprocessor settings. This is shown below using the hello_world SDK example project.

PrintNegativeFloats.png

Let me know if this solution works for you. If not, could you provide more details on your environment to help find a solution?

 

Regards,

Kaleb Belete

在原帖中查看解决方案

2 回复数
4,662 次查看
felix1
Contributor IV

Hi Kaleb,

Thanks for your right answer.

I want to ask another question about floating point number. 

I use CMSIS DSP library to do FFT (fast Fourier transform), this transform will use real number and complex number.

I use "Redlib (nohost-nf)" library now, and it seems ok to compile FFT API like "arm_rfft_fast_f32()".

Do I need to change the "Redlib (nohost-nf)" to another library for using floating point number?

0 项奖励
回复
4,663 次查看
kbelete
NXP Employee
NXP Employee

Hi Felix,

Negative floating point values can be printed by opening the Project Properties and defining both “PRINTF_FLOAT_ENABLE” and “PRINTF_ADVANCED_ENABLE” to 1 in the Preprocessor settings. This is shown below using the hello_world SDK example project.

PrintNegativeFloats.png

Let me know if this solution works for you. If not, could you provide more details on your environment to help find a solution?

 

Regards,

Kaleb Belete