31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.2 Rational Numbers ( rational )<br />

1. Definition<br />

An instance q of type rational is a rational number where the numerator and the denominator<br />

are both of type integer.<br />

#include < <strong>LEDA</strong>/numbers/rational.h ><br />

2. Creation<br />

rational q; creates an instance q of type rational.<br />

rational<br />

rational<br />

rational<br />

q(integer n);<br />

q(integer n, integer d);<br />

q(double x);<br />

creates an instance q of type rational and initializes it with the<br />

integer n.<br />

creates an instance q of type rational and initializes it to the rational<br />

number n/d.<br />

creates an instance q of type rational and initializes it with the<br />

value of x.<br />

3. Operations<br />

<strong>The</strong> arithmetic operations +, −, ∗, /, + =, − =, ∗ =, / =, −(unary), ++, −−, the<br />

comparison operations =, ==, ! = and the stream operations are all available.<br />

void q.negate( ) negates q.<br />

void q.invert( ) inverts q.<br />

rational q.inverse( ) returns the inverse of q.<br />

integer q.numerator( ) returns the numerator of q.<br />

integer q.denominator( ) returns the denominator of q.<br />

rational& q.simplify(const integer& a)<br />

rational& q.normalize( ) normalizes q.<br />

simplifies q by a.<br />

Precondition: a divides the numerator and the denominator<br />

of q.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!