Code Block |
---|
#ifndef SRMATH_H
#define SRMATH_H
#include <QObject>
class Srmath : public QObject
{
Q_OBJECT
public:
explicit Srmath(QObject *parent = 0);
double Abs(double in){if(in<0.0)return in*(-1.0); else return in;}
qint8 Abs(qint8 in){if(in<0)return in*(-1); else return in;}
qint16 Abs(qint16 in){if(in<0)return in*(-1); else return in;}
qint32 Abs(qint32 in){if(in<0)return in*(-1); else return in;}
qint8 isPositive(qint8 in){if(in<0)return -1; else return 1;}
qint16 isPositive(qint16 in){if(in<0)return (-1); else return 1;}
qint32 isPositive(qint32 in){if(in<0)return (-1); else return 1;}
double Saturate(double in,double limit);
bool AbsSmaller(double input,double limit;
bool AbsLarger(double input,double limit);
bool AbsLargerAndSameSign(double input,double limit);
double RaiseAbsLimit(double input,double *limit);
double LowerAbsLimit(double input,double *limit);
signals:
public slots:
}; |
Code Block |
---|
#include "srmath.h" Srmath::Srmath(QObject *parent) : QObject(parent) { } double Srmath::Saturate(double in,double limit) { if(in>limit){ return limit; } else if(in<-limit){ return -limit; } else return in; } bool Srmath::AbsSmaller(double input,double limit) { if(Abs(input)<Abs(limit))return true; else return false; } bool Srmath::AbsLarger(double input,double limit) { if(Abs(input)>Abs(limit))return true; else return false; } // molempien arvojen oltava samanmerkkisia, ehto toteutuu kun tullaan nollasta ylä- tai alarajalle bool Srmath::AbsLargerAndSameSign(double input,double limit) { return (Abs(input) > Abs(limit))&&((input*limit)>0); } //! jos tulo on absoluuttisesti suurempi kuin raja, funktio nostaa rajaa double Srmath::RaiseAbsLimit(double input,double *limit) { if(Abs(input)>Abs(*limit)){ *limit=Abs(input); } return *limit; } double Srmath::LowerAbsLimit(double input,double *limit) { if(Abs(input)<Abs(*limit)){ *limit=Abs(input); } return *limit; } |