float help

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys, I have a small piece of code to display the percentage of a routine that's complete.  However it does not display the float...

Have a look at the piece of code.

 

        	if((++progress % 100) == 0){

        		float percentage_complete = 100.0 / ((float)(nCol * nRow) / progress);

        		printf("\r %i- %i - %3.2f", (nRow * nCol), progress, percentage_complete);
        	}

Help!!!

 

Oh, I've tried using sprint.

 

 

EDITED, the other two integers display correctly, namely, "(nRow * nCol), progress".

Last Edited: Mon. Nov 18, 2019 - 05:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Some toolchains have options for printf - this is due to float and the fancier options adding quite a bit of code. If float isn't enabled, guess what? It don't print floats!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If using avr-gcc, then you'll need to add the following to the linker options to gain access to the float-aware printf:

-Wl,-u,vfprintf -lprintf_flt

Steve

Maverick Embedded Technologies Ltd. Home of Maven and wAVR.

Maven: WiFi ARM Cortex-M Debugger/Programmer

wAVR: WiFi AVR ISP/PDI/uPDI Programmer

https://www.maverick-embedded.co...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As the others have said, this can depend on what toolchain you're using!

 

So - what toolchain are you using ?

 

Fianawarrior wrote:
it does not display the float

As in nothing at all? blanks? other?

 

Fianawarrior wrote:
I've tried using sprint

And what was the result?

 

How about posting some examples of the output you do get?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

First skill of engineering is being able to report faults in a professional engineering manner ;-)

 

Words like "doesn't work" do not make useful fault reports !

 

Usually a useful fault report consists of actions tried, result expected, result actually received.

 

I'm guessing you are actually talking a bout some ARM system here. As other have said, many systems have multiple implementations of vfprintf to cater for resources available and often a lower spec. version is the default. Having said that, if this is a powerful ARm system I would have thought they would not consider resources to be a limit and the default would be all singing, all dancing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
if((++progress % 100) == 0){

        		float percentage_complete = 100.0 / ((float)(nCol * nRow) / progress);

        		printf("\r %d- %d - %3.2f", (nRow * nCol), progress, percentage_complete);
        	}

 
change  %i to %d

 

If you don't want to use the float module

 

if((++progress % 100) == 0){

                 percentage_complete = 10000 / ((nCol * nRow) / progress);

                printf("\r %d- %d - %3d.%2d", (nRow * nCol), progress, percentage_complete/100 , percentage_complete % 100 );
            }

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


krisfrost wrote:

change  %i to %d

Go on. Exactly how would that change anything?

 

http://www.cplusplus.com/reference/cstdio/printf/

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Usually a useful fault report consists of actions tried, result expected, result actually received

And details of what was used.

 

Quote:
if this is a powerful ARm system I would have thought they would not consider resources to be a limit and the default would be all singing, all dancing.

Indeed.

 

But it's not uncommon with Cortex-M (especially the low-end ones) to find "restricted" printf options ...

 

EDIT

 

https://community.atmel.com/forum/samc21-printf-not-printing-float-values

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Mon. Nov 18, 2019 - 02:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm pretty sure he's mentioned Cortex-A previously in fact. On an "A" I would expect every last variant of every last function to work as it's a "full PC" ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, he has - but has also mentioned working on other stuff, too.

 

ISTR Cortex-M being mentioned  recently ?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You'll no doubt be pleased to know your code works fine on my Ubuntu machine.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RARRRR!!!!!!!!!!!!

Windows 10 here mate.  I'm using a bog standard toolchain, I think "cygwin64".  Will "arm-none-eabi" be any different?

 

Oh the processor is a SAMA5D44.

 

 

Think I'll just rite my own float routine.

Last Edited: Mon. Nov 18, 2019 - 10:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I think it's time to read the documentation. Don't re-invent the wheel poorly if you don't need to.

 

Might be something here:

 

https://stackoverflow.com/questi...

 

 

 

Last Edited: Mon. Nov 18, 2019 - 10:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

how said it will be poorly implemented?  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dyslexia rules KO!

 

Anyways, what run time lib do you link against? LibC or Newlib? or something else?? The documentation for the respective lib will tell you what to do.

Last Edited: Tue. Nov 19, 2019 - 02:55 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

who! cheeky