PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > any simple class for rational numbers?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
any simple class for rational numbers?

Réponse
 
LinkBack Outils de la discussion
Vieux 08/02/2008, 13h10   #1
Leslaw Bieniasz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut any simple class for rational numbers?



Hi,

I need a simple class implementing rational numbers
as fractions of integers, together with arithmetic
operations on such fractions, checks for overflow, etc.
Any suggestions?

L.B.


!!! PLEASE NOTE MY NEW ADDRESS SINCE January 1st, 2008, INDICATED BELOW !!!
*-------------------------------------------------------------------*
| Dr. Leslaw Bieniasz, |
| Institute of Physical Chemistry of the Polish Academy of Sciences,|
| Department of Complex Systems and Chemical |
| Processing of Information |
| ul. Niezapominajek 8, 30-239 Cracow, Poland. |
| tel. (personal) +48 (12) 6395212 |
| tel./fax. (secretariat) +48 (12) 4251923 |
| E-mail: nbbienia@cyf-kr.edu.pl |
*-------------------------------------------------------------------*
| Interested in Computational Electrochemistry? |
| Visit my web site: http://www.cyf-kr.edu.pl/~nbbienia |
*-------------------------------------------------------------------*
  Réponse avec citation
Vieux 08/02/2008, 13h35   #2
Hans Mull
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: any simple class for rational numbers?

Leslaw Bieniasz schrieb:
>
> Hi,
>
> I need a simple class implementing rational numbers
> as fractions of integers, together with arithmetic
> operations on such fractions, checks for overflow, etc.
> Any suggestions?
>
> L.B.
>
>
> !!! PLEASE NOTE MY NEW ADDRESS SINCE January 1st, 2008, INDICATED BELOW !!!
> *-------------------------------------------------------------------*
> | Dr. Leslaw Bieniasz, |
> | Institute of Physical Chemistry of the Polish Academy of Sciences,|
> | Department of Complex Systems and Chemical |
> | Processing of Information |
> | ul. Niezapominajek 8, 30-239 Cracow, Poland. |
> | tel. (personal) +48 (12) 6395212 |
> | tel./fax. (secretariat) +48 (12) 4251923 |
> | E-mail: nbbienia@cyf-kr.edu.pl |
> *-------------------------------------------------------------------*
> | Interested in Computational Electrochemistry? |
> | Visit my web site: http://www.cyf-kr.edu.pl/~nbbienia |
> *-------------------------------------------------------------------*

I don't know if you think this is simple, but I worked with GMP some
time ago. mpq_t is a rational number class.

Kind regards
  Réponse avec citation
Vieux 08/02/2008, 13h48   #3
Juha Nieminen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: any simple class for rational numbers?

Leslaw Bieniasz wrote:
> I need a simple class implementing rational numbers
> as fractions of integers, together with arithmetic
> operations on such fractions, checks for overflow, etc.
> Any suggestions?


I think that in the time it took you to write this and the time it
will take for someone to write an useful answer, you could have written
such a simple class yourself... :P
  Réponse avec citation
Vieux 08/02/2008, 13h50   #4
Hans Mull
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: any simple class for rational numbers?

Juha Nieminen schrieb:
> Leslaw Bieniasz wrote:
>> I need a simple class implementing rational numbers
>> as fractions of integers, together with arithmetic
>> operations on such fractions, checks for overflow, etc.
>> Any suggestions?

>
> I think that in the time it took you to write this and the time it
> will take for someone to write an useful answer, you could have written
> such a simple class yourself... :P

Maybe he has some special requirements, like a very efficient libary or
arbitrary precision support...
  Réponse avec citation
Vieux 08/02/2008, 14h16   #5
shazled@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: any simple class for rational numbers?

On Feb 8, 1:10pm, Leslaw Bieniasz <nbbie...@cyf-kr.edu.pl> wrote:
> I need a simple class implementing rational numbers
> as fractions of integers, together with arithmetic
> operations on such fractions, checks for overflow, etc.
> Any suggestions?
>


I haven't used it myself, but boost provides one that seems to fit
your requirements:
http://www.boost.org/libs/rational/index.html

Saul

  Réponse avec citation
Vieux 08/02/2008, 16h22   #6
Christopher Dearlove
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: any simple class for rational numbers?

"Juha Nieminen" <nospam@thanks.invalid> wrote in message
news:47ac59c0$0$23817$4f793bc4@news.tdc.fi...
> Leslaw Bieniasz wrote:
>> I need a simple class implementing rational numbers
>> as fractions of integers, together with arithmetic
>> operations on such fractions, checks for overflow, etc.
>> Any suggestions?

>
> I think that in the time it took you to write this and the time it
> will take for someone to write an useful answer, you could have written
> such a simple class yourself... :P


From past conversation with the author of the Boost Rational class (which
I have however never used) I know that there's more to it than that. Just
to take one detail, you probably want to store it in simplest form (e.g. 3/4
rather than 6/8) which reduces the chances of overflow when using finite
length integers. In fact you want to do some such manipulation during,
say, addition so that you don't overflow when you don't have to, even if a
naive implementation might. (It's possible for two numbers to be safe, their
sum to be safe, but the obvious implementation to overflow during the
calculation. I don't know if t's always possible to avoid that.) And of
course you want to do that efficiently (no more often than necessary). I
don't know all the details. I understand that, as ever, Knuth is the
starting
point.


  Réponse avec citation
Vieux 08/02/2008, 19h46   #7
Juha Nieminen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: any simple class for rational numbers?

Christopher Dearlove wrote:
> "Juha Nieminen" <nospam@thanks.invalid> wrote in message
> news:47ac59c0$0$23817$4f793bc4@news.tdc.fi...
>> Leslaw Bieniasz wrote:
>>> I need a simple class implementing rational numbers
>>> as fractions of integers, together with arithmetic
>>> operations on such fractions, checks for overflow, etc.
>>> Any suggestions?

>> I think that in the time it took you to write this and the time it
>> will take for someone to write an useful answer, you could have written
>> such a simple class yourself... :P

>
> From past conversation with the author of the Boost Rational class (which
> I have however never used) I know that there's more to it than that. Just
> to take one detail, you probably want to store it in simplest form (e.g. 3/4
> rather than 6/8) which reduces the chances of overflow when using finite
> length integers. In fact you want to do some such manipulation during,
> say, addition so that you don't overflow when you don't have to, even if a
> naive implementation might. (It's possible for two numbers to be safe, their
> sum to be safe, but the obvious implementation to overflow during the
> calculation. I don't know if t's always possible to avoid that.) And of
> course you want to do that efficiently (no more often than necessary). I
> don't know all the details. I understand that, as ever, Knuth is the
> starting
> point.


It was just a joke.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h45.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14716 seconds with 15 queries