This repository has been archived on 2025-02-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Pivot/src/NR.h
Pierre CHATAIGNER c7268fe536 nombres rationnels
2024-02-25 13:06:11 +01:00

42 lines
1.1 KiB
C++

#pragma once
#include <iostream>
class NR {
private:
int m_Numerator;
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); //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);