begin process at 2012 02 07 10:47:06
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Maths & Algorithmes

 > BIG SIGNED INTEGER

BIG SIGNED INTEGER


 Information sur la source

Note :
4,67 / 10 - par 3 personnes
4,67 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Maths & Algorithmes Niveau :Expert Date de création :14/02/2004 Vu / téléchargé :4 236 / 180

Auteur : tibur

Ecrire un message privé
Commentaire sur cette source (8)
Ajouter un commentaire et/ou une note

 Description

Un entier de taille non definie. Je poste le code du header, histoire de vous donner une idée.

Source

  • #ifndef BIGINT_INC
  • #define BIGINT_INC
  • #include <assert.h>
  • #include <iostream>
  • #include <list>
  • #ifndef MAX
  • #define MAX(a,b) ((a>b)?a:b)
  • #endif
  • #ifndef MIN
  • #define MIN(a,b) ((a<b)?a:b)
  • #endif
  • class BigInt
  • {
  • public:
  • typedef unsigned char Byte;
  • BigInt();
  • ~BigInt();
  • BigInt(const BigInt & br);
  • BigInt(unsigned int i);
  • void operator = (const BigInt & br);
  • void operator = (unsigned int i);
  • void operator = (int i);
  • BigInt operator * (const BigInt & br)const;
  • BigInt operator * (unsigned int i)const;
  • BigInt operator * (Byte b)const;
  • BigInt operator + (unsigned int i)const;
  • BigInt operator + (const BigInt & br)const;
  • BigInt operator - (const BigInt & br)const;
  • BigInt operator - ()const;
  • BigInt operator << (unsigned int i) const;
  • void operator *= (const BigInt & br);
  • void operator *= (unsigned int i);
  • void operator += (const BigInt & br);
  • void operator += (unsigned int i);
  • void operator -= (const BigInt & br);
  • void operator -= (unsigned int i);
  • void operator /= (const BigInt & br);
  • void operator ++ ();
  • void operator -- ();
  • bool operator ==(const BigInt & br)const;
  • bool operator !=(const BigInt & br)const;
  • bool operator <(const BigInt & br)const;
  • bool operator >(const BigInt & br)const;
  • bool operator <=(const BigInt & br)const;
  • bool operator >=(const BigInt & br)const;
  • static void div(BigInt & q, BigInt & r, const BigInt & f, const BigInt & d);
  • static BigInt gcd(BigInt & a, BigInt & b);
  • void print(std::ostream & out)const;
  • double to_double() const;
  • static void test();
  • private:
  • std::list<Byte> data_;
  • bool positiv_;
  • };
  • inline std::ostream & operator << (std::ostream & out, const BigInt & bi){
  • bi.print(out);
  • return out;
  • }
  • #endif
#ifndef BIGINT_INC
#define BIGINT_INC


#include <assert.h>
#include <iostream>
#include <list>

#ifndef MAX
#define MAX(a,b) ((a>b)?a:b)
#endif

#ifndef MIN
#define MIN(a,b) ((a<b)?a:b)
#endif


class BigInt
{
public:
	typedef unsigned char Byte;

	BigInt();
	~BigInt();
	BigInt(const BigInt & br);
	BigInt(unsigned int i);

	void operator = (const BigInt & br);
	void operator = (unsigned int i);
	void operator = (int i);

	BigInt operator * (const BigInt & br)const;
	BigInt operator * (unsigned int i)const;
	BigInt operator * (Byte b)const;
	BigInt operator + (unsigned int i)const;
	BigInt operator + (const BigInt & br)const;
	BigInt operator - (const BigInt & br)const;
	BigInt operator - ()const;

	BigInt operator << (unsigned int i) const;

	void operator *= (const BigInt & br);
	void operator *= (unsigned int i);
	void operator += (const BigInt & br);
	void operator += (unsigned int i);
	void operator -= (const BigInt & br);
	void operator -= (unsigned int i);
	
	void operator /= (const BigInt & br);
	void operator ++ ();
	void operator -- ();

	bool operator ==(const BigInt & br)const;
	bool operator !=(const BigInt & br)const;
	bool operator <(const BigInt & br)const;
	bool operator >(const BigInt & br)const;
	bool operator <=(const BigInt & br)const;
	bool operator >=(const BigInt & br)const;

	static void div(BigInt & q, BigInt & r, const BigInt & f, const BigInt & d);
	static BigInt gcd(BigInt & a, BigInt & b);

	void print(std::ostream & out)const;

	double to_double() const;

	static void test();
private:
	
	std::list<Byte> data_;
	bool positiv_;
};
inline std::ostream & operator << (std::ostream & out, const BigInt & bi){
	bi.print(out);
	return out;
}
#endif

 Conclusion

Bug connu (!) : l'affichage par la fonction print est en hexa ... Y en a que ca derrange ? :)

Bug inconnus : yup, pleins ! enfin, j'espere que non ...

J'ai aussi une classe Fraction qui est le rapport de 2 de ces BigInt. Mais le code est encore buggy...

Sinon, l'algo de la division est vraiment TRES POURRIS ! (comprendre PAS RAPIDE)

tib

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip TIMER
ECRITURE / LECTURE EN C++
SMART POINTER
DE L'IMPORTANCE DES ASSERT
STL : LA CLASSE MAP (EXEMPLE D'UN AGENDA)

 Sources de la même categorie

Source avec Zip UN EXAMPLE D'APPLICATION EN CUDA DE L'ALGORITHME DE SCAN POU... par oguzaras
Source avec Zip Source avec une capture CHIFFREMENT DE VIGENERE par lajouad
Source avec Zip Source avec une capture ANALYSE SYNTAXIQUE par lajouad
Source avec Zip Source avec une capture STRUCTURE D'UNE MATRICE PAR LES LISTE LINÉAIRE (NON CONTUGUS... par benzarabel
Source avec Zip Source avec une capture DESSINER UNE ARBRE BINAIRE( MODE CONSOLE): par benzarabel

Commentaires et avis

Commentaire de vecchio56 le 15/02/2004 13:57:47 administrateur CS

oui moi ca me dérange que les nombres soient affichée en hexa, mais en fait c'est plutot toi qui doit avoir un pb pour les afficher en décimal je pense. Tu devrais aussi faire un constructeur qui prend un chaine de caractères

Commentaire de Kirua le 15/02/2004 14:24:17

je trouve que c'est une excellente idée d'écrire cette classe, et c'est très bien d'avoir surchargé l'opéro &lt;&lt; de la std, bon boulot :-)

Commentaire de BjarneStroustrup le 15/02/2004 18:07:33

et l'opérateur &gt;&gt; ???

Commentaire de dominion le 16/02/2004 22:40:26

BjarneStroustrup : Bah c'est une source libre de droit tu peux le faire toi même ;-) ça doit pas être bien difficile...
tibur : Chapeau j'ai pas tout regardé mais ça a l'air vachement bien fait ! Par contre c'est pas un peu exagéré de mettre ça en Expert ?

Commentaire de koolj le 03/03/2004 17:59:23

Moi aussi j'en ai fais une et pour moi aussi la fonction de division est méga lourde (en temps d'exécution).

Par contre l'affichage peut se faire dans les bases comprises entre 2 et 36, et l'opérateur istream&gt;&gt; est programmé (un peu maladroitement).

le plus étrange dans tout ca que que je n'avais pas regarder cet article pour programmer ma classe et pourtant on croirait le contraire en la regardant lol.

Je ne l'ai pas encore posté car je dois finir la gestion automatique de la taille de l'entier, les tests de bugs et les tests de performances.

Je le posterais dans le courant de la semaine...

Commentaire de Kirua le 03/03/2004 18:04:41

tiens si d'autres pensent à écrire leur classe, ils peuvent jeter un coup d'oeil du côté de l'en-tête &lt;bitset&gt; (STD -&gt; super optimisé).

c'est un conteneur un peu spécial pour gérer des listes de bits (booléens mais gérés intelligemment, sur un bit, pas sur un octet comme le sont les bool standards).

Commentaire de vecchio56 le 03/03/2004 20:03:07 administrateur CS

de toute facon à la fin tu ne eux pas avoir de trucs dont la taille n'est pas un multiple de 8 bits

Commentaire de vecchio56 le 03/03/2004 20:05:05 administrateur CS

par ailleurs j'ai aussi crée cette classe et j'aimerais bien avoir quelques commentaires pour savoir ce que vous en pensez
http://www.cppfrance.com/code.aspx?ID=19105

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,577 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales