Jump to content
hyperion007

Float Round Fround() Not Supported?

Recommended Posts

Hi,

 

I'm trying to round a floating point variable and would like to use fround() but it seems that it is not supported by BoostC. Currently the variable has 6 decimal places and I would like to get that down to two.

 

Any plans on supporting this any time soon? I'm using BoostC through Flowcode.

Share this post


Link to post
Share on other sites

Hello,

 

I too would like to see the fround function as well as proper native floating point support in BoostC.

 

Functions like sin, cos, tan, atan2 etc would also be nice.

 

AVR/Arduino current wins out on all these fronts but would be great to have these functions available in BoostC too.

Share this post


Link to post
Share on other sites

Totally agree with this. Not having proper floating point support really hurts. I develop test equipment and enjoy using boostC, having a proper float would make things so much easier and keep me from constantly looking at other products to get the job done.

Share this post


Link to post
Share on other sites

Can we please get a reply to this? I really need to be able to round floating point numbers.

 

For example:

 

If I do some calculations on data from a temperature sensor, I need the 6 digit precision but for the final result to be printed to the display it makes no sense to print all 6 decimal places.

 

And I cannot just ignore the last 4-5 digits because it would not be accurate enough.

Share this post


Link to post
Share on other sites

hyperion007,

I'm trying to round a floating point variable and would like to use fround() but it seems that it is not supported by BoostC. Currently the variable has 6 decimal places and I would like to get that down to two.

I don't believe that fround() is a standard 'C' function, is it?

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hi

 

Building a rounding function is not that dificult.

 

 

1 - Multiply by 10 to the power of intended number of decimal places.

2 - Add 0.5

3 - Truncate the result (can be done by simple type casting to long)

4 - Divide by the same value used to multiply in step 1.

 

For simple truncation, without 4/5 rounding, skip step 2.

 

 

Its up to each one of us to choose if we make it a function or a macro.

 

 

If it is for printing only.

In step 3 convert it to long.

Convert the long to string and insert the decimal symbol at the correct position in the string.

 

 

 

 

Just my 2 cents...

 

Best regards

Jorge

Edited by JorgeF

Share this post


Link to post
Share on other sites

Building a rounding function is not that dificult.

 

Sure building your own function to do a specific job is easy enough if you have the time to mess about. Same as I could cut the grass on my lawn with a pair of scissors if I needed to. Thankfully there are other compilers available for PIC with lawnmowers build in as standard. e.g. floating point.

 

What about ......

 

Functions like sin, cos, tan, atan2 etc would also be nice.

Share this post


Link to post
Share on other sites

Hi

 

It looks like I didn't explain myself properly.

What is a real showstopper is the number of instructions and processing time it tooks for any 8 bit PIC to process floating point operations and trigonometric functions.

 

If I can't do without, I simply climb the stairs to a PIC24 or PIC32, but so far that has been very very rare.

 

I usually make an intermediate step betwen the specs and the code, its called the "firmware project".

 

On most of my projects I manage to use integer maths in place of floating point ones, its a matter of using the "really needed" precision.

Even 64 bit integer maths are way faster to process and have smaller code size than the simplest floating point counterpart.

 

As for triogometric functions, well the table lookup approach has been my workhorse.

It takes only a 256 entry table to give me a 1024 step resolution of a full 360º cycle (0.25 degrees per step) for both Sin and Cos functions.

And its way faster and smaller than any kind of floating point approach to the subject.

 

At least for me, this kind of strategy has been getting the job done for more than 20 years....

 

 

If it doesn't we can always get support from mister "Sun Tzu"

After all his integer maths worked for the greek astronomical calculations back in the 5th century.......way before the invention of the microprocessor.......and still work today for RSA and other forms of security encription.

http://en.wikipedia.org/wiki/Chinese_remainder_theorem

 

 

 

Just my 2 cents....

 

Best regards

Jorge

Edited by JorgeF

Share this post


Link to post
Share on other sites

As BoostC doesn't seem interested in a fully featured compiler there have been multiple floating point trig routines written inside the Flowcode software itself showing it is possible.

 

http://www.matrixtsl.com/mmforums/viewtopic.php?f=58&t=14814

 

I agree floating point is overkill for most 8-bit applications but that doesn't seem to have stopped any of the other PIC compilers from fully implementing support.

 

Its all about consistency and BoostC just isn't consistent, plus it's mega slow to compile compared to a free tool like GCC.

 

Just written a program for a Stewart platform using AVR GCC. Loads and loads of floating point calculations to do inverse kinematics and it works like a charm. No way I would even attempt this in BoostC.

Edited by assasinsareus

Share this post


Link to post
Share on other sites

Hi

 

Nobody ever said its impossible, only its too heavy on an 8 bit PIC.

When I can't get ride of floating point maths, I move on to a PIC24, dsPIC33 or PIC32 and use the XC* compilers from Microchip, even in free mode as the PICs have enought processing power to deal with the lack of optimization.

 

Just my 2 cents...

 

 

Best regards

Jorge

Edited by JorgeF

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×