Skip to content

Commit

Permalink
Trac #27812: py3: fix comparison of constants
Browse files Browse the repository at this point in the history
of pi < pi in particular

URL: https://trac.sagemath.org/27812
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager authored and vbraun committed May 20, 2019
2 parents 925119d + b30879a commit fe1c495
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/sage/symbolic/comparison.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ cpdef int mixed_order(lhs, rhs) except -2:
sage: mixed_order(SR(oo), sqrt(2))
1
"""
if lhs is rhs:
return 0
if not is_Expression(lhs):
lhs = SR(lhs)
if not is_Expression(rhs):
Expand Down
13 changes: 8 additions & 5 deletions src/sage/symbolic/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@
# version 2 or any later version. The full text of the GPL is available at:
# http://www.gnu.org/licenses/
###############################################################################
from __future__ import print_function
from __future__ import absolute_import
from __future__ import print_function, absolute_import

import math
from functools import partial
from sage.rings.infinity import (infinity, minus_infinity,
unsigned_infinity)
from sage.structure.richcmp import richcmp_method, op_EQ, op_GE, op_LE

constants_table = {}
constants_name_table = {}
Expand Down Expand Up @@ -263,6 +263,7 @@ def unpickle_Constant(class_name, name, conversions, latex, mathml, domain):
cls = globals()[class_name]
return cls(name=name)

@richcmp_method
class Constant(object):
def __init__(self, name, conversions=None, latex=None, mathml="",
domain='complex'):
Expand Down Expand Up @@ -292,7 +293,7 @@ def __init__(self, name, conversions=None, latex=None, mathml="",

register_symbol(self.expression(), self._conversions)

def __eq__(self, other):
def __richcmp__(self, other, op):
"""
EXAMPLES::
Expand All @@ -306,8 +307,10 @@ def __eq__(self, other):
sage: p != s
True
"""
return (self.__class__ == other.__class__ and
self._name == other._name)
if self.__class__ == other.__class__ and self._name == other._name:
return op in [op_EQ, op_GE, op_LE]
else:
return NotImplemented

def __reduce__(self):
"""
Expand Down

0 comments on commit fe1c495

Please sign in to comment.