avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] linear regression on 128L


From: Ben L. Titzer
Subject: Re: [avr-gcc-list] linear regression on 128L
Date: Mon, 4 Apr 2005 15:06:57 -0700


On Apr 3, 2005, at 3:41 PM, intiha Ho gai wrote:

Hi,
Having found out that the avr-gcc lib supports floats and handles them
quite gracefully, I tried porting my linear regression code from
desktop on to the atmega 128L, more or less as is. For testing i used
the same table of X and Y values as sample inputs to the algorithm.

 Now I am using microsecond granularity as input to the regression
engine and since the values are fairly large - and since there are sum
of products- I get fairly large numbers (If i do the same on my
desktop, the biggest number i get is sumXSq=7260107358192.000000). Now
I know that doubles are 4 bytes - and i was thinking that would not be
enough - Any way around this?.


Double precision floating point numbers should be 64 bits--8 bytes, on all desktop platforms. Did you declare your variables as double or as float? It might be a limitation in the floating point emulation library of gcc--it may only support floats, when you in fact want doubles. Ask yourself if you need that much precision in your results. A standard floating point number gives something like 22 or 24 bits of precision (about 7 decimal places). If you're guiding a missile with a 600 mile range, the representation of distance is accurate down to 1 foot resolution.

Also, if precision is an issue, you may want to carefully review your code to avoid potential roundoff problems (e.g. adding or subtracting 3 numbers in the wrong order can amplify round off problems).

Btw when i do print the same result over the serial port (from my
embedded port) I get something like sumXSq=7260108000000.000000 - same
but with 6 of the last significant decimal points lost after
rounding). Any suggestions? Please note that currently optimization
isnt an issue, I just want to get it to run and even if it monstrously
slow, I just have to do this once every boot up!

I would appreciate any help.

Best Regards.
Affan.


_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


========================================================
Whenever anyone says, "theoretically," they really mean, "not really."
--Dave Parnas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]