# Forum: ARM programming with GCC/GNU tools Floating point Calculations problem in GCC

 Author: Atul B. (atul) Posted on: 2007-11-02 20:28

Rate this post
 0 ▲ useful ▼ not useful
Hello All,

Im working on a GPS application. Im compiling the code using GCC
Compiler to make mod. Im using WinARM 4.1.1. I have not used GCC before.
Im facing the problem in floating point calculations. All floating point
calculations are not performed correctly.

e.g. If I write something like this:

fSec *= 200000;
where fSec is a double variable and contains some value.

the result Im getting is not correct. When I compile the code using ARM
I get the correct result. I also tried libraries provided by GCC like
libc.a and libgcc.a. Still I got the incorrect results.

Its very argent for me. Can anyone help me to solve this problem?

Thanks in advance...

 Author: Clifford S. (clifford) Posted on: 2007-11-03 10:29

Rate this post
 0 ▲ useful ▼ not useful
Since many people are using floating point successfully, simply saying
you are getting incorrect results (without showing any significant code,
without explaining the result you expected and the result you got, how
you observed the result or what your build options were) is not going to

1) Provide a complete but simple example of some code you are using that
does not perform as you expect.

2) For that code provide the answer you got and the answer you expected.

3) If it is not included in the code, explain how you observed the
result. (It may be an issue in the way you are observing it rather that
teh actual value itself).

4) Provide a transcript of the build log resulting from the code

You need to bear in mind the accuracy of floating point representations,
and the manner in which functions such as printf() format such values
for display. The value may contain small fractional components that
printf() for example does not display. When you multiply that value by a
large number, that fractional component may become significant. Moreover
not all values are exactly representable - the fact that teh
representation has 64bits but the number of possible real values is
infinite should tell you that. So a value that is not exactly
represented may have a small error. In certain calculations such errors
can accumulate and grow to become significant. This issue is most
prevalent when a calculation involves a combination of very large and
very small values.

Google "floating point accuracy" to get an idea of what might be
ocurring. Specifically:
http://www.cprogramming.com/tutorial/floating_poin...

Clifford

 Author: Joel J. (jomed) Posted on: 2008-06-22 13:51

Rate this post
 0 ▲ useful ▼ not useful
Atul Bhagat wrote:
> Hello All,
>
> Im working on a GPS application. Im compiling the code using GCC
> Compiler to make mod. Im using WinARM 4.1.1. I have not used GCC before.
> Im facing the problem in floating point calculations. All floating point
> calculations are not performed correctly.
>
> e.g. If I write something like this:
>
> fSec *= 200000;
> where fSec is a double variable and contains some value.
>
> the result Im getting is not correct. When I compile the code using ARM
> I get the correct result. I also tried libraries provided by GCC like
> libc.a and libgcc.a. Still I got the incorrect results.
>
> Its very argent for me. Can anyone help me to solve this problem?
>

I think I am facing the same issue regarding floating Point with
Yagarto.
Did you solved it?
If yes, could you send me the solution?
I thank you in advance.

 Author: Clifford S. (clifford) Posted on: 2008-06-22 16:44

Rate this post
 0 ▲ useful ▼ not useful
Joel Jomed wrote:
>
> I think I am facing the same issue regarding floating Point with
> Yagarto.
> Did you solved it?
> If yes, could you send me the solution?
> I thank you in advance.

This is a very old thread you have posted to, the OP chose not to
because the answer was useful, it may be that it was not that important
to him after all, or quite possibly he was just too rude to respond.

Either way, the same response applies, (did you even read my response!?)
You need to provide further information as suggested. Since there are so
many things that can go wrong with floating point, the chances are that
you don't have the same problem, and that his solution if he had one
might not apply to your situation. How can we tell? Neither of you have
provided sufficient information.

Clifford

 Author: Joel J. (jomed) Posted on: 2008-06-25 15:18

Rate this post
 0 ▲ useful ▼ not useful
Clifford Slocombe wrote:
> Joel Jomed wrote:
>>
>> I think I am facing the same issue regarding floating Point with
>> Yagarto.
>> Did you solved it?
>> If yes, could you send me the solution?
>> I thank you in advance.
>
> This is a very old thread you have posted to, the OP chose not to
> because the answer was useful, it may be that it was not that important
> to him after all, or quite possibly he was just too rude to respond.
>
> Either way, the same response applies, (did you even read my response!?)
> You need to provide further information as suggested. Since there are so
> many things that can go wrong with floating point, the chances are that
> you don't have the same problem, and that his solution if he had one
> might not apply to your situation. How can we tell? Neither of you have
> provided sufficient information.
>
> Clifford

Clifford,
I posted a more general enquiry named "Yagarto and floating point" in
this forum. This post was only sent because Mr Atul Bhagat seem to have
the same issue and in case he had the solution.

• $formula (LaTeX syntax)$