add PIFixedPoint
git-svn-id: svn://db.shs.com.ru/pip@98 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -20,25 +20,27 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "picout.h"
|
||||
|
||||
#ifndef PIFIXEDPOINT_H
|
||||
#define PIFIXEDPOINT_H
|
||||
template<int Precision = 0, typename Type = int>
|
||||
class FixedPoint {
|
||||
class PIFixedPoint {
|
||||
// friend PICout operator <<(PICout s, const FixedPoint<> & v);
|
||||
public:
|
||||
typedef FixedPoint<Precision, Type> fp;
|
||||
FixedPoint(const Type &v = Type()) {val = fpv(v);}
|
||||
FixedPoint(const fp &v) {val = v.val;}
|
||||
FixedPoint(const float &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));}
|
||||
FixedPoint(const double &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));}
|
||||
typedef PIFixedPoint<Precision, Type> fp;
|
||||
PIFixedPoint(const Type &v = Type()) {val = fpv(v);}
|
||||
PIFixedPoint(const fp &v) {val = v.val;}
|
||||
PIFixedPoint(const float &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));}
|
||||
PIFixedPoint(const double &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));}
|
||||
// FixedPoint(const long double &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));}
|
||||
|
||||
template<typename T>
|
||||
fp & operator=(const T & v) {val = fpv(Type(v)); return *this;}
|
||||
fp & operator=(const fp & v) {val = v.val; return *this;}
|
||||
fp & operator=(const float &v) {val = FixedPoint(v).val; return *this;}
|
||||
fp & operator=(const double &v) {val = FixedPoint(v).val; return *this;}
|
||||
fp & operator=(const long double &v) {val = FixedPoint(v).val; return *this;}
|
||||
fp & operator=(const float &v) {val = PIFixedPoint(v).val; return *this;}
|
||||
fp & operator=(const double &v) {val = PIFixedPoint(v).val; return *this;}
|
||||
fp & operator=(const long double &v) {val = PIFixedPoint(v).val; return *this;}
|
||||
fp & operator-() {fp p = fp(*this); p.val = -val; return p;}
|
||||
bool operator==(const fp & v) const {val == v.val;}
|
||||
bool operator!=(const fp & v) const {val != v.val;}
|
||||
@@ -73,8 +75,9 @@ public:
|
||||
Type val;
|
||||
};
|
||||
|
||||
|
||||
template<int Precision, typename Type>
|
||||
inline PICout operator <<(PICout s, const FixedPoint<Precision, Type> & v) {
|
||||
inline PICout operator <<(PICout s, const PIFixedPoint<Precision, Type> & v) {
|
||||
s.space(); s.setControl(0, true);
|
||||
if (Precision == 0) s << v.val;
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user