Search |
 |
|
 |
| Author |
Message |
|
|
Posted: Nov 06, 2009 - 05:14 PM |
|

Joined: Nov 17, 2004
Posts: 13815
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.
|
| |
|
|
|
|
|
Posted: May 16, 2010 - 08:44 PM |
|


Joined: Nov 09, 2001
Posts: 268
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.  |
|
|
| |
|
|
|
|
|
Posted: May 16, 2010 - 09:38 PM |
|

Joined: Sep 05, 2001
Posts: 2496
|
|
|
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.
Peter |
|
|
| |
|
|
|
|
|
Posted: May 17, 2010 - 02:28 PM |
|


Joined: Nov 09, 2001
Posts: 268
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;
|
|
|
| |
|
|
|
|
|
Posted: May 18, 2010 - 03:58 PM |
|


Joined: Apr 25, 2004
Posts: 3808
Location: Denmark
|
|
|
|
|
|
|
|
|
|