-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Récupération code fraction + inversion matrice
- Loading branch information
Showing
10 changed files
with
214 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/*************************************************************/ | ||
/* Fractionizer */ | ||
/*-----------------------------------------------------------*/ | ||
/* Module : fractionizer.h */ | ||
/* Numéro de version : 0.0.23 */ | ||
/* Date : 24/08/2015 */ | ||
/* Auteurs : ajneu */ | ||
/*************************************************************/ | ||
|
||
#ifndef FRACTIONIZER_H | ||
#define FRACTIONIZER_H | ||
|
||
|
||
|
||
#include <cmath> // std::modf | ||
#include <vector> | ||
|
||
|
||
/* uncomment one of the following */ | ||
//#define OWN_LIMITS | ||
#undef OWN_LIMITS | ||
|
||
|
||
#ifndef OWN_LIMITS | ||
#include <limits> | ||
using std::numeric_limits; | ||
|
||
#else | ||
|
||
#include <cfloat> // FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON | ||
|
||
// just for fun | ||
namespace own { | ||
template <typename Tfl> // Tfl should be a floating point type (preferably double or long double) | ||
struct numeric_limits { | ||
static constexpr Tfl min() { | ||
return get_min(Tfl{}); | ||
} | ||
static constexpr Tfl epsilon() { | ||
return get_epsilon(Tfl{}); | ||
} | ||
private: | ||
static constexpr float get_min(float) { return FLT_MIN; } | ||
static constexpr double get_min(double) { return DBL_MIN; } | ||
static constexpr long double get_min(long double) { return LDBL_MIN;} | ||
|
||
static constexpr float get_epsilon(float) { return FLT_EPSILON; } | ||
static constexpr double get_epsilon(double) { return DBL_EPSILON; } | ||
static constexpr long double get_epsilon(long double) { return LDBL_EPSILON;} | ||
}; | ||
} | ||
|
||
using own::numeric_limits; | ||
|
||
#endif | ||
|
||
|
||
|
||
|
||
class Fractionizer { | ||
public: | ||
template <typename Tfl, typename Tfl2> // Tfl should be a floating point type (preferably double or long double) | ||
static std::vector<Tfl> fractionize(const Tfl val, Tfl2 &num, Tfl2 &denom) | ||
{ | ||
Tfl n; | ||
Tfl d; | ||
std::vector<Tfl> vec; | ||
Tfl i; | ||
Tfl v = val; | ||
goto label_begin; | ||
do { | ||
v = 1/v; | ||
label_begin: | ||
//std::cout << "v == " << v << '\t'; | ||
v = std::modf(v, &i); | ||
//std::cout << "i == " << i << '\t'; | ||
vec.push_back(i); | ||
//std::cout << "calc == " << Fractionizer::calc_frac<Tfl>(vec, n, d) << std::endl; | ||
} | ||
//while (std::abs((Fractionizer::calc_frac<Tfl>(vec, n, d) - val)/val) > numeric_limits<Tfl>::min()); | ||
while (Fractionizer::calc_frac<Tfl>(vec, n, d) != val); | ||
//assert((n/d) == val); | ||
num = n; | ||
denom = d; | ||
return vec; | ||
} | ||
|
||
template <typename Tfl, typename Tfl2> // Tfl should be a floating point type (preferably double or long double) | ||
static Tfl calc_frac(const std::vector<Tfl> &vec, Tfl2 &num, Tfl2 &denom) | ||
// {2, 3, 4} | ||
// 2 + 1/(3+1/4) | ||
{ | ||
if (!vec.empty()) { | ||
Tfl n = 1.0; // num | ||
Tfl d = 0.0; // denom | ||
|
||
auto it_end = vec.cend(); | ||
const auto it_beg = vec.cbegin(); | ||
do { | ||
--it_end; | ||
|
||
std::swap(n, d); | ||
n += *it_end * d; | ||
} while (it_end != it_beg); | ||
num = n; | ||
denom = d; | ||
return n/d; | ||
} | ||
num = 0.0; | ||
denom = 1.0; | ||
return 0.0; | ||
} | ||
|
||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
CC = g++ | ||
GCC = g++ | ||
CFLAGS = -g -Wall | ||
TARGET = calculatriceMatrice_CPP | ||
OBJS = obj/main.o obj/matrice.o | ||
|
||
G++ = -g -Wall | ||
all: $(OBJS) | ||
$(GCC) $(CFLAGS) -o $(TARGET) $(OBJS) | ||
|
||
Sources = Calculatrice_Matrice_CPP/sources | ||
obj/main.o: sources/main.cpp headers/matrice.h | ||
#check if obj directory exists, if not create it | ||
@if [ ! -d "obj" ]; then mkdir obj; fi | ||
$(GCC) $(CFLAGS) -c sources/main.cpp -o obj/main.o | ||
|
||
obj = Calculatrice_Matrice_CPP/obj | ||
|
||
all: $(obj)/main.o $(obj)/matrice.o | ||
$(CC) $(G++) $(obj)/main.o $(obj)/matrice.o -o calculatrice_matrice_CPP | ||
|
||
$(obj)/main.o: | ||
$(CC) $(G++) -c $(Sources)/main.cpp -o $(obj)/main.o | ||
|
||
$(obj)/matrice.o: | ||
$(CC) $(G++) -c $(Sources)/matrice.cpp -o $(obj)/matrice.o | ||
obj/matrice.o: sources/matrice.cpp headers/matrice.h headers/fractionizer.h | ||
$(GCC) $(CFLAGS) -c sources/matrice.cpp -o obj/matrice.o | ||
|
||
clean: | ||
rm -f $(obj)/*.o calculatrice_matrice_CPP | ||
rm -f $(OBJS) $(TARGET) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*************************************************************/ | ||
/* Calculatrice_Matrice_CPP */ | ||
/*-----------------------------------------------------------*/ | ||
/* Module : main.cpp */ | ||
/* Numéro de version : 0.0.13 */ | ||
/* Date : 19/04/2022 */ | ||
/* Auteurs : Lilian CHARDON, Andréas CASTELLO */ | ||
/*************************************************************/ | ||
|
||
|
||
#include "../headers/matrice.h" | ||
|
||
int main() | ||
{ | ||
Matrice* matrice1 = new Matrice("Matrice 1", 5, 5, ALEATOIRE); | ||
//Matrice* matrice2 = new Matrice("Matrice 2", 5, 5, ALEATOIRE); | ||
matrice1->afficherMatrice(10); | ||
//matrice2->afficherMatrice(10); | ||
|
||
Matrice* matriceInversee = matrice1->inverserMatrice("Matrice 1 inversée"); | ||
matriceInversee->afficherMatrice(10); | ||
|
||
cout << "Nombre de matrice créées : " << Matrice::nbMatriceCrees << endl; | ||
|
||
delete matrice1; | ||
//delete matrice2; | ||
delete matriceInversee; | ||
|
||
cout << "Nombre de matrice détruites : " << Matrice::nbMatriceDetruites << endl; | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters