Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
py3: introducing __round__ methods as alias for existing .round
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Chapoton committed Oct 3, 2018
1 parent a1bfef8 commit 27cfe85
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/sage/rings/number_field/number_field_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,8 @@ cdef class NumberFieldElement(FieldElement):

return (self + QQ((1,2))).floor()

__round__ = round

def abs(self, prec=None, i=None):
r"""Return the absolute value of this element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):

def round(self):
r"""
Returns the round (nearest integer).
Return the round (nearest integer).
EXAMPLES::
Expand Down Expand Up @@ -2314,6 +2314,9 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
else:
return n

__round__ = round


cdef class OrderElement_quadratic(NumberFieldElement_quadratic):
"""
Element of an order in a quadratic field.
Expand Down
2 changes: 2 additions & 0 deletions src/sage/rings/qqbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4748,6 +4748,8 @@ def round(self):
"""
return self._floor_ceil(lambda x: x.round())

__round__ = round

def trunc(self):
r"""
Round ``self`` to the nearest integer toward zero.
Expand Down
2 changes: 2 additions & 0 deletions src/sage/rings/real_double.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,8 @@ cdef class RealDoubleElement(FieldElement):
"""
return Integer(round(self._value))

__round__ = round

def floor(self):
"""
Return the floor of ``self``.
Expand Down
2 changes: 2 additions & 0 deletions src/sage/rings/real_mpfi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2997,6 +2997,8 @@ cdef class RealIntervalFieldElement(RingElement):
"""
return self.parent()(self.lower().round(), self.upper().round())

__round__ = round

def trunc(self):
r"""
Return the truncation of this interval as an interval
Expand Down
2 changes: 2 additions & 0 deletions src/sage/rings/real_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,8 @@ cdef class RealNumber(sage.structure.element.RingElement):
mpfr_round(x.value, self.value)
return x.integer_part()

__round__ = round

def floor(self):
"""
Return the floor of ``self``.
Expand Down
2 changes: 2 additions & 0 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6025,6 +6025,8 @@ cdef class Expression(CommutativeRingElement):
else:
return result

__round__ = round

def function(self, *args):
"""
Return a callable symbolic expression with the given variables.
Expand Down

0 comments on commit 27cfe85

Please sign in to comment.