Oskar Weigl / fixedpoint

Files at this revision

API Documentation at this revision

Comitter:
madcowswe
Date:
Sun Nov 27 05:10:45 2011 +0000
Parent:
0:ca79fb4a8165
Commit message:
Made it possible to cast to double

Changed in this revision

fixed_class.h Show annotated file Show diff for this revision Revisions of this file
--- 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