Changes between Initial Version and Version 1 of Ticket #24225, comment 10


Ignore:
Timestamp:
11/16/17 15:45:05 (3 years ago)
Author:
embray
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #24225, comment 10

    initial v1  
    77--- a/src/sage/rings/integer.pyx
    88+++ b/src/sage/rings/integer.pyx
    9 @@ -656,12 +656,15 @@ cdef class Integer(sage.structure.element.EuclideanDomainEleme
    10              if isinstance(x, Integer):
    11                  set_from_Integer(self, <Integer>x)
    12 
    13 -            elif isinstance(x, int):
    14 -                mpz_set_si(self.value, PyInt_AS_LONG(x))
    15 -
    16              elif isinstance(x, long):
    17                  mpz_set_pylong(self.value, x)
    18 
    19 +            elif isinstance(x, int):
    20 +                # This case shouldn't occur on Python 3 where long is int
    21 +                # Only on Python 2 are they different types (or it is safe to
    22 +                # cast a Python int to a machine long without overflow)
    23 +                mpz_set_si(self.value, PyInt_AS_LONG(x))
    24 +
    25              elif isinstance(x, float):
    26                  n = long(x)
    27                  if n == x:
    289@@ -926,13 +929,14 @@ cdef class Integer(sage.structure.element.EuclideanDomainEleme
    2910             c = mpz_cmp((<Integer>left).value, (<Integer>right).value)
     
    5536         if type(x) is type(y):
    5637             if not mpz_sgn((<Integer>y).value):
    57 diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx
    58 index 9d778c8..712a0ea 100644
    59 --- a/src/sage/rings/integer_ring.pyx
    60 +++ b/src/sage/rings/integer_ring.pyx
    61 @@ -610,10 +610,11 @@ cdef class IntegerRing_class(PrincipalIdealDomain):
    62              sage: f(a) # random
    63              5
    64          """
    65 -        if S is int:
    66 -            return sage.rings.integer.int_to_Z()
    67 -        elif S is long:
    68 +        if S is long:
    69              return sage.rings.integer.long_to_Z()
    70 +        elif S is int:
    71 +            # Note: This case should never occur on Python 3 where long is int
    72 +            return sage.rings.integer.int_to_Z()
    73          elif S is bool:
    74              return True
    75          elif is_numpy_type(S):
    7638}}}
     39
     40Edit: Originally a few of these diffs were the same as in #24221, but I think the ones here now are still new...