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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

Jump to solution
4,279 Views
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

Labels (1)
1 Solution
4,182 Views
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

View solution in original post

2 Replies
4,182 Views
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 Kudos
Reply
4,183 Views
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