Python_2  1.0
Public Member Functions | Public Attributes | List of all members
_01a_fracao.Fracao Class Reference

A simple class for creating fraction objects (rational numbers). More...

Public Member Functions

def __init__ (self, num=1, den=1)
 Constructor. More...
 
def __eq__ (self, f)
 Operator ==. More...
 
def __add__ (self, f)
 Operator +. More...
 
def __radd__ (self, f)
 Operador right side addition. More...
 
def __iadd__ (self, f)
 Operator +=. More...
 
def __mul__ (self, f)
 Operator *. More...
 
def __rmul__ (self, f)
 Operador right side multiplication. More...
 
def __div__ (self, f)
 Operator /. More...
 
def __truediv__ (self, f)
 Operator /. More...
 
def __floordiv__ (self, f)
 Operator //. More...
 
def __rdiv__ (self, f)
 Operador right side integer division (python 2). More...
 
def __rtruediv__ (self, f)
 Operador right side float division (python 3). More...
 
def __rfloordiv__ (self, f)
 Operador right side integer division. More...
 
def __sub__ (self, f)
 Operator -. More...
 
def __rsub__ (self, f)
 Operador right side subtraction. More...
 
def __neg__ (self)
 Operator -. More...
 
def __str__ (self)
 Controls how a fraction is printed. More...
 
def simplifica (self)
 Simplifies this fraction, by dividing either the numerator or the denominator by its gcd. More...
 

Public Attributes

 num
 Numerator. More...
 
 den
 Denominator. More...
 

Detailed Description

A simple class for creating fraction objects (rational numbers).

Constructor & Destructor Documentation

◆ __init__()

def _01a_fracao.Fracao.__init__ (   self,
  num = 1,
  den = 1 
)

Constructor.

Parameters
numnumerator.
dendenominator
Constructor

Member Function Documentation

◆ __add__()

def _01a_fracao.Fracao.__add__ (   self,
  f 
)

◆ __div__()

def _01a_fracao.Fracao.__div__ (   self,
  f 
)

Operator /.

Returns
self / f when future.division is not in effect.

◆ __eq__()

def _01a_fracao.Fracao.__eq__ (   self,
  f 
)

Operator ==.

References _01a_fracao.Fracao.simplifica().

◆ __floordiv__()

def _01a_fracao.Fracao.__floordiv__ (   self,
  f 
)

Operator //.

Returns
self // f.

References _01a_fracao.Fracao.den, and _01a_fracao.Fracao.num.

◆ __iadd__()

def _01a_fracao.Fracao.__iadd__ (   self,
  f 
)

◆ __mul__()

def _01a_fracao.Fracao.__mul__ (   self,
  f 
)

◆ __neg__()

def _01a_fracao.Fracao.__neg__ (   self)

Operator -.

References _01a_fracao.Fracao.den, and _01a_fracao.Fracao.num.

◆ __radd__()

def _01a_fracao.Fracao.__radd__ (   self,
  f 
)

Operador right side addition.

This method is only called if the left object does not have an add method, or that method does not know how to add the two objects (which it flags by returning NotImplemented).

◆ __rdiv__()

def _01a_fracao.Fracao.__rdiv__ (   self,
  f 
)

Operador right side integer division (python 2).

This method is only called if the left object does not have a div method, or that method does not know how to add the two objects (which it flags by returning NotImplemented).

References _01a_fracao.Fracao.__rfloordiv__().

◆ __rfloordiv__()

def _01a_fracao.Fracao.__rfloordiv__ (   self,
  f 
)

Operador right side integer division.

This method is only called if the left object does not have a floordiv method, or that method does not know how to add the two objects (which it flags by returning NotImplemented).

References _01a_fracao.Fracao.den, and _01a_fracao.Fracao.num.

Referenced by _01a_fracao.Fracao.__rdiv__(), and _01a_fracao.Fracao.__rtruediv__().

◆ __rmul__()

def _01a_fracao.Fracao.__rmul__ (   self,
  f 
)

Operador right side multiplication.

This method is only called if the left object does not have a mul method, or that method does not know how to add the two objects (which it flags by returning NotImplemented).

◆ __rsub__()

def _01a_fracao.Fracao.__rsub__ (   self,
  f 
)

Operador right side subtraction.

This method is only called if the left object does not have a sub method, or that method does not know how to add the two objects (which it flags by returning NotImplemented).

◆ __rtruediv__()

def _01a_fracao.Fracao.__rtruediv__ (   self,
  f 
)

Operador right side float division (python 3).

This method is only called if the left object does not have a truediv method, or that method does not know how to add the two objects (which it flags by returning NotImplemented).

References _01a_fracao.Fracao.__rfloordiv__().

◆ __str__()

def _01a_fracao.Fracao.__str__ (   self)

Controls how a fraction is printed.

Returns
a string: numerator/denominator, or only the numerator, if the denominator is 1, after simplification, or 0, if the numerator is null.

References _01a_fracao.Fracao.den, and _01a_fracao.Fracao.num.

◆ __sub__()

def _01a_fracao.Fracao.__sub__ (   self,
  f 
)

Operator -.

◆ __truediv__()

def _01a_fracao.Fracao.__truediv__ (   self,
  f 
)

Operator /.

Returns
self / f when future.division is in effect.

◆ simplifica()

def _01a_fracao.Fracao.simplifica (   self)

Simplifies this fraction, by dividing either the numerator or the denominator by its gcd.

References _01a_fracao.Fracao.den, _01a_fracao.mdc(), and _01a_fracao.Fracao.num.

Referenced by _01a_fracao.Fracao.__eq__(), and _01a_fracao.Fracao.__iadd__().

Member Data Documentation

◆ den

_01a_fracao.Fracao.den

◆ num

_01a_fracao.Fracao.num

The documentation for this class was generated from the following file: