nombres rationnels
This commit is contained in:
36
src/NR.h
36
src/NR.h
@@ -1,12 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class NR {
|
||||
private:
|
||||
int m_Numerator;
|
||||
int m_Denominator;
|
||||
int m_Denominator; //has to be > 0, sign is carried by the numerator
|
||||
|
||||
public:
|
||||
NR() : m_Numerator(0), m_Denominator(1) {}
|
||||
NR(int entier) : m_Numerator(entier), m_Denominator(1) {}
|
||||
NR(int numerator, int denominator) : m_Numerator(numerator), m_Denominator(denominator) {}
|
||||
};
|
||||
NR(int numerator, int denominator); //check if denominator != 0
|
||||
void NRset(int numerator, int denominator); //same
|
||||
|
||||
void reduceNR(); //divide by PGCD, not automatically called yet
|
||||
void invertNR();
|
||||
|
||||
int NRgetNum() const;
|
||||
int NRgetDen() const;
|
||||
NR& operator =(const NR& opNR);
|
||||
|
||||
bool operator ==(const NR& opNR) const;
|
||||
bool operator <(const NR& opNR) const;
|
||||
bool operator >(const NR& opNR) const;
|
||||
|
||||
bool operator !=(const NR& opNR) const;
|
||||
bool operator <=(const NR& opNR) const;
|
||||
bool operator >=(const NR& opNR) const;
|
||||
|
||||
friend std::ostream& operator <<(std::ostream& os, const NR& opNR);
|
||||
friend std::istream& operator >>(std::istream& os, NR& opNR);
|
||||
|
||||
NR operator +(const NR& opNR) const;
|
||||
NR operator -(const NR& opNR) const;
|
||||
NR operator *(const NR& opNR) const;
|
||||
NR operator /(const NR& opNR) const;
|
||||
|
||||
static void test();
|
||||
};
|
||||
|
||||
int PGCD(int x, int y);
|
||||
Reference in New Issue
Block a user