GY-63_MS5611/libraries/Fraction/fraction.h
rob tillaart 507f1edd61 + version 0.1.05
+ tested negative Fractions math
+ added missing constructors,
+ refactoring,
2015-03-01 12:15:35 +01:00

69 lines
1.3 KiB
C++

//
// FILE: fraction.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.04
// PURPOSE: demo library for fractions for Arduino
// URL:
//
// Released to the public domain
//
#ifndef Fraction_h
#define Fraction_h
#include "Arduino.h"
#define FRACTIONLIBVERSION "0.1.04"
class Fraction: public Printable
{
public:
Fraction(double);
Fraction(int32_t, int32_t);
Fraction(int32_t);
Fraction(int16_t);
Fraction(int8_t);
Fraction(uint32_t);
Fraction(uint16_t);
Fraction(uint8_t);
Fraction(const Fraction&);
size_t printTo(Print& p) const;
// equalities
bool operator == (Fraction);
bool operator != (Fraction);
bool operator > (Fraction);
bool operator >= (Fraction);
bool operator < (Fraction);
bool operator <= (Fraction);
// negation
Fraction operator - ();
Fraction operator + (Fraction);
Fraction operator - (Fraction);
Fraction operator * (Fraction);
Fraction operator / (Fraction);
void operator += (Fraction);
void operator -= (Fraction);
void operator *= (Fraction);
void operator /= (Fraction);
double toDouble();
// double toPercentage();
private:
void simplify();
double fractionize(double);
int32_t gcd(int32_t, int32_t);
int32_t n;
int32_t d;
};
#endif
//
// -- END OF FILE --
//