Main Overview

# Class `Rational`

Class `Rational`: Rational numbers
Rational(p, q) Example: `Rational(3,17)`
Rational(n) Example: `Rational(3)`
Rational(s) Example: `Rational("3/17")`
For `Rational` objects the arithmetical operators +, -, *, / are defined.

Overview:

## Constructor

Rational (p, q=1)

## Operators

Operator | Meaning
abs(x) |
x + y | Addition
x / y | a / b à a.__div__(b), if a is of type Rational b.__rdiv__(a), otherwise
x == y |
float(x) |
x // y |
int(x) |
long(x) |
x * y | a * b à a.__mul__(b), if a is of type Rational b.__rmul__(a), otherwise
x != y |
-x | -a à a.__neg__()
str(x) |
x - y | a - b à a.__sub__(b), if a is of type Rational b.__rsub__(a), otherwise
x / y |

## Object Methods

Method | Meaning
abs () | absolute value
copy () | independent copy ("clone") of r
isInteger () |
operators () | For documentation only
toFloat () | Conversion to floating point number
toInt () | Round to the nearest integer
toStr () | Representation as string

# Constructor

### Rational

Constructor

Usage: `Rational(p, q=1)`

# Operators

### abs(x)

absolute value

Usage: `abs(x)`

### x + y

a.__add__(b)

Usage: `x + y`

Description:
Addition
Also operator notation: a + b
Instead of `a = a + b` you can write `a += b`.

### x / y

exact Division

Usage: `x / y`

Description:
a / b à a.__div__(b), if a is of type Rational b.__rdiv__(a), otherwise

### x == y

Usage: `x == y`

### float(x)

Conversion to floating point number

Usage: `float(x)`

### x // y

Usage: `x // y`

### int(x)

Round to the nearest integer

Usage: `int(x)`

### long(x)

Round to the nearest integer

Usage: `long(x)`

### x * y

Multiplication:

Usage: `x * y`

Description:
a * b à a.__mul__(b), if a is of type Rational b.__rmul__(a), otherwise

### x != y

Usage: `x != y`

### -x

Unary operator -

Usage: `-x`

Description:
-a à a.__neg__()

### str(x)

Object representation as string

Usage: `str(x)`

Description:

### x - y

Subtraction:

Usage: `x - y`

Description:
a - b à a.__sub__(b), if a is of type Rational b.__rsub__(a), otherwise

### x / y

Usage: `x / y`

# Object Methods

### abs

r.abs()

Usage: `self.abs()`

Description:
absolute value
Also as global function: abs(r)

### copy

r.copy()

Usage: `self.copy()`

Description:
independent copy ("clone") of r

### isInteger

Usage: `self.isInteger()`

### operators

Rational.operators()

Usage: `self.operators()`

Description:
For documentation only
The following operators are defined in the class Rational:

Op. | Function | Examples
--- | --- | ---
+ | Addition | `a + b; a += b`
- | Subtraction | `a - b; a -= b`
* | Multiplication | `a * b; a *= b`
/ | Division | `a / b; a /= b`
- | Unary minus | `-a`
< > <= >= | Comparision operators |

This method is for documentation only. It has no effect.

### toFloat

r.toFloat()

Usage: `self.toFloat()`

Description:
Conversion to floating point number
Also as global function: float(r)

### toInt

r.toInt()

Usage: `self.toInt()`

Description:
Round to the nearest integer
Also as global function: int(r)

### toStr

r.toStr()

Usage: `self.toStr()`

Description:
Representation as string
Also as global function: str(r)