A fixed point library from Trenki http://www.trenki.net/content/view/17/1/ Slightly modified so that the fixed point data structure can automatically cast itself to float or int when used in an expression, and added the functionality to cast between precisions.

Revision:
1:ac99b6f474a0
Parent:
0:ca79fb4a8165
--- a/fixed_class.h	Sun Nov 27 00:28:31 2011 +0000
+++ b/fixed_class.h	Sun Nov 27 05:10:45 2011 +0000
@@ -80,10 +80,11 @@
     fixed_point operator / (int32_t r) const { fixed_point x = *this; x /= r; return x;}
     operator int()         const { return intValue>>p; }
     operator float()       const { return fix2float<p>(intValue); }
+    operator double()       const { return (double)intValue / (1 << p); }
     
     //Added casting and constructing from another precision
     template <int q>
-	fixed_point(const fixed_point<q> &r) : intValue(q <= p ? r.intValue << (p - q) : r.intValue >> (q - p)) {}
+    fixed_point(const fixed_point<q> &r) : intValue(q <= p ? r.intValue << (p - q) : r.intValue >> (q - p)) {}
 };
 
 // Specializations for use with plain integers