EmbDev.net

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


von Atul B. (atul)


Rate this post
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...

von Clifford S. (clifford)


Rate this post
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
help you get an answer.

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
compilation and linking.


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.newton.dep.anl.gov/newton/askasci/1993/compsci/CS6.HTM
http://www.cprogramming.com/tutorial/floating_point/understanding_floating_point.html

Clifford

von Joel J. (jomed)


Rate this post
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?
>
> Thanks in advance...

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.

von Clifford S. (clifford)


Rate this post
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
respond to my answer with a request for more information. That may be
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

von Joel J. (jomed)


Rate this post
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
> respond to my answer with a request for more information. That may be
> 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,
Thanks for your repply.
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.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.