Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Koshchi
PostPosted: Nov 06, 2009 - 05:14 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 15127
Location: Vancouver, BC

Quote:
> I see 9 decimal digits. 32 bit floats are good for about 8.5

Well, they are usually stated as 6...7 digits of precision.

IEEE754 is 24 bits, so a little over 7 decimal digits at best.

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
avra
PostPosted: May 16, 2010 - 08:44 PM
Hangaround


Joined: Nov 09, 2001
Posts: 287
Location: Serbia

Hello Simone,

I have just finished fix64 library for AvrCo Multitasking Pascal compiler www.e-lab.de/AVRco/index_en.html. It handles s31.32 fixed point numbers and covers range from -2147483648.000000000 to 2147483647.999999999. I guess that covers your demands quite well. It is not yet officially in AvrCo but it will be pretty soon. Standard compiler version will support all standard operators and conversions so code will look the same as when floating point numbers are used, and professional version will cover much more functions.

Here is complete list of functions implemented:
Fix64ToString(), Fix64ToStrFmt(), Fix64Sgn(), Fix64Sign(), FloatToFix64(), Fix64ToFloat(), Fix64Sqr(), Fix64Sqrt(), Fix64Mod(), Fix64ModInt(), Fix64Lower(), Fix64Higher(), Fix64Abs(), Fix64ValueTrimLimit(), Fix64ValueInRange(), Fix64Sin(), Fix64Cos(), Fix64SinD(), Fix64CosD(), Fix64SinCos(), Fix64RadToDeg(), Fix64DegToRad(), Fix64Quadrant(), Fix64Tan(), Fix64TanD(), Fix64Frac(), Fix64Int(), Fix64Trunc(), Fix64Odd(), Fix64Even(), Fix64Round(), Fix64ArcTan(), Fix64ArcTanD(), Fix64ArcSin(), Fix64ArcSinD(), Fix64ArcCos(), Fix64ArcCosD(), Fix64ArcTan(), Fix64ArcTanD(), Fix64ArcTan2(), Fix64ArcTan2D(), Fix64Within(), Fix64ValueInTolerance(), Fix64ValueInToleranceP(), Fix64Cot(), Fix64CotD(), Fix64ArcCot(), Fix64ArcCotD(), Fix64IsPowOfTwo(), Fix64Ln(), Fix64Log10(), Fix64Log(), Fix64Exp(), Fix64Power(), Fix64PowerInt(), Fix64Integrate(), Fix64Sinh(), Fix64Cosh(), Fix64Tanh(), Fix64ArSinh(), Fix64ArCosh(), Fix64ArTanh(), Fix64Sec(), Fix64Cosec().

Last year I have made a free AFP - Arbitrary Fixed Point library for fix32 math and published it here as a project. It has much less functions then fix64 commercial implementation but you can get the picture of what's going on. You can take a look at it here:
http://www.avrfreaks.net/index.php?modu ... em_id=2351
and nice screenshot of some of the fix32 features can be seen here:
http://www.avrfreaks.net/modules/Freaks ... enshot.gif

Besides GPS and astronomy, a common use for such precision is often undervalued flow metering. For example, you measure natural gas flow in a pipe few times per second, and you just add it cumulative to some total, and of course you use standard 32 bit floating point for this. Then, after many months your customer calls you and says that your nicely calibrated readings are giving wrong totals when daily, weekly or monthly reports are made. That happens because 32 bit floating point can not handle situation when really small numbers are beeing added to really big numbers. That's where fix64 comes to the rescue. Very Happy
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
danni
PostPosted: May 16, 2010 - 09:38 PM
Raving lunatic


Joined: Sep 05, 2001
Posts: 2617


avra wrote:
I have just finished fix64 library for AvrCo Multitasking Pascal compiler www.e-lab.de/AVRco/index_en.html. It handles s31.32 fixed point numbers and covers range from -2147483648.000000000 to 2147483647.999999999. I guess that covers your demands quite well.


I fear, it covers not the point, that it must be called from C code and compileable using Winavr. Crying or Very sad


Peter
 
 View user's profile Send private message  
Reply with quote Back to top
avra
PostPosted: May 17, 2010 - 02:28 PM
Hangaround


Joined: Nov 09, 2001
Posts: 287
Location: Serbia

danni wrote:
I fear, it covers not the point, that it must be called from C code and compileable using Winavr.

This is from the original post:
cicciociccio wrote:
Can you suggest me some library or in alternative any solutions in order to solve my issue?

Besides, looking at free sources of fix32, he can implement C version of just +,-,*,/ for his own fix64 quite easy (if that is all he needs, and probably it is such a case). For example, I don't think that this is unreadable to an average C programer:
Code:
function fixAdd(const a, b: TFix): TFix;
begin // add a and b with fixed point math
  Return (a + b);
end;

function fixMul(const a, b: TFix): TFix;
begin // multiply a and b with fixed point math
  Return (longint((int64(a) * int64(b)) shr fixFractBits));
end;
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Bingo600
PostPosted: May 18, 2010 - 03:58 PM
Raving lunatic


Joined: Apr 25, 2004
Posts: 3947
Location: Denmark

This thread (German) has an avr-gcc package
64 Bit float Emulator in C, IEEE754 compatibel


http://www.mikrocontroller.net/topic/85256

You would need this archive http://www.mikrocontroller.net/attachme ... double.zip
And replace avr_f64.c in the archive with this one http://www.mikrocontroller.net/attachme ... /avr_f64.c

I just made a "test compile" , and it's around 21K Flash / 310 B Ram on a Mega32

/Bingo
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits