Hauptübersicht

Klasse Rational

Klasse Rational: Rationale Zahl
Rational(p, q) Beispiel: Rational(3,17)
Rational(n) Beispiel: Rational(3)
Rational(s) Beispiel: Rational("3/17")
Rational-Objekte können mit den arithmetischen Operatoren +, -, *, / verknüpft werden.

Übersicht:

Konstruktor

Rational (p, q=1)

Operatoren

OperatorBedeutung
abs(x)
x + yAddition
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

Objektmethoden

MethodeBedeutung
abs ()Absolutbetrag
copy ()unabhängige Kopie von r
isInteger ()
operators ()Nur zur Dokumentation
toFloat ()Konvertierung in Gleitkommazahl
toInt ()Rundung zur nächsten ganzen Zahl
toStr ()Darstellung als String

Konstruktor

Rational

Konstruktor

Aufruf: Rational(p, q=1)


Operatoren

abs(x)

Absolutbetrag

Aufruf: abs(x)


x + y

a.__add__(b)

Aufruf: x + y

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


x / y

exact Division

Aufruf: x / y

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


x == y

Aufruf: x == y


float(x)

Umwandlung in Gleitkommazahl

Aufruf: float(x)


x // y

Aufruf: x // y


int(x)

Auf-/Abrundung zur nächsten Ganzzahl

Aufruf: int(x)


long(x)

Auf-/Abrundung zur nächsten Ganzzahl

Aufruf: long(x)


x * y

Multiplication:

Aufruf: x * y

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


x != y

Aufruf: x != y


-x

Unary operator -

Aufruf: -x

Beschreibung:
-a à a.__neg__()


str(x)

Object representation as string

Aufruf: str(x)

Beschreibung:


x - y

Subtraction:

Aufruf: x - y

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


x / y

Aufruf: x / y


Objektmethoden

abs

r.abs()

Aufruf: self.abs()

Beschreibung:
Absolutbetrag
Auch globale Funktion: abs(r)


copy

r.copy()

Aufruf: self.copy()

Beschreibung:
unabhängige Kopie von r


isInteger

Aufruf: self.isInteger()


operators

Rational.operators()

Aufruf: self.operators()

Beschreibung:
Nur zur Dokumentation
Die Klasse Rational erlaubt folgende Operatoren:

Op.FunktionBeispiele
+Additiona + b; a += b
-Subtraktiona - b; a -= b
*Multiplikationa * b; a *= b
/Divisiona / b; a /= b
-unäres Minus-a
< > <= >=Vergleichsoperatoren
Diese Methode dient nur zur Dokumentation. Sie hat keine Wirkung.


toFloat

r.toFloat()

Aufruf: self.toFloat()

Beschreibung:
Konvertierung in Gleitkommazahl
Auch globale Funktion: float(r)


toInt

r.toInt()

Aufruf: self.toInt()

Beschreibung:
Rundung zur nächsten ganzen Zahl
Auch globale Funktion: int(r)


toStr

r.toStr()

Aufruf: self.toStr()

Beschreibung:
Darstellung als String
Auch globale Funktion: str(r)