Forum Discussion
11 Replies
- Altera_Forum
Honored Contributor
How are you trying to print it? I believe the libc employed by Nios II supports %f, %e, and %g. Keep in mind that the "small" or code reduced versions won't support floating point at all...
Regards, slacker - Altera_Forum
Honored Contributor
portion of my code:
--- Quote Start --- dma_tick = (unsigned int)(end_dma - start_dma); pio_tick = (unsigned int)(end_pio - start_pio); freq = (unsigned int)(alt_timestamp_freq()); improve = (((pio_tick - dma_tick)/pio_tick) *100); printf("Printing report..\n\n"); printf("******* System Performance Analysis *******\n"); printf("Data size tested : %d Bytes\n", (length*4)); printf("Number of ticks per second : %u\n", freq); printf("Without DMA: Number of ticks: %u\n", pio_tick); printf("DMA: Number of ticks : %u\n", dma_tick); printf("* System Performance Improvement: %lf\n", improve); --- Quote End --- i cant print improve... i am using full lib, not small or reduced.. - Altera_Forum
Honored Contributor
how have you defined pio_tick and dma_tick? if you have non floating point in a division in C the integer aritmetic is used.
int a = 195; int b = 100; float c; a - b=95 c = 95/100 = 0 try putting casts to float (float)(a-b)/(float)a - Altera_Forum
Honored Contributor
Yeah! it works! Thanks!
- Altera_Forum
Honored Contributor
...what gabrigob wrote... It's a type issue that you're hitting here. I'd play around with that until you get it to work.
Note that it is _definitely_ possible. I was the maintainer of the software for a 10g design (https://www.altera.com/support/software/download/refdesigns/ip/interface/dnl-10gbe-hardware-demo.jsp), for a bit, and did just this successfully in order to display the massive numbers related to packet-based stats. Also, I wasn't aware that the %lf was valid. I'm pretty sure the length modifier is only valid when printing integer values. Regards, slacker - Altera_Forum
Honored Contributor
An integer divided by another integer regardless of how it's stored will be an integer result typecast to whatever the storage variable is after the operator completes. So after the division you would be left with an integer value of 0 which converted to floating point is just 0.0.
More info: http://en.wikipedia.org/wiki/type_conversion - Altera_Forum
Honored Contributor
slacker: yeah... i changed lf to f... thanks!
BadOmen: thanks for the info! - Altera_Forum
Honored Contributor
Hi,
I have the problem that the floating point numbers are always printed as -ÿÿÿ.ÿÿÿÿÿÿ on the console window :( My code is, where f[z] is an array of floats f[z] = 2.0*f[z]/(412.0) - 1.0; f[z] = f[z] * 1024.0; printf ("\n %0f", (float)f[z]); the printf prints all other formats correctly like integers and chars ... thanks - Altera_Forum
Honored Contributor
Are you using the small newlib C library? The small library doesn't support printing floating point values. Search for "footprint" in the Nios II software developer's handbook for more details.
If that's not the case perhaps you are running low on memory and the stack and heap are colliding. - Altera_Forum
Honored Contributor
Hi,
I am not using the small c library! How can I increase the amount of memory allocated for the stack, heap? thanks