Ticket #229 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

Cython % operator on cdef int has C semantics, not Python semantics

Reported by: cwitty Owned by: robertwb
Priority: blocker Milestone: 0.12
Component: Code Generation Keywords:
Cc:

Description

That is,

  cdef int a = -1
  cdef int b = 16
  a % b

gives -1, where Python would give 15.

This bit a new Sage developer, who was using the result as an index into a C array and got a segfault by indexing off the beginning.

I'm not sure whether this should be changed, but if not, it should be prominently documented; I couldn't find any mention in the documentation (but maybe I didn't look in the right place?).

Change History

Changed 4 years ago by dagss

We've got a lot of feedback for which semantics Cython should have here; unfortunately there's no clear consensusl; many feel that Python semantics is natural and others that C semantics is natural.

sage-devel poll:  http://groups.google.com/group/sage-devel/browse_thread/thread/be9e2ef6a9745575 numpy-discuss poll:  http://thread.gmane.org/gmane.comp.python.numeric.general/28726 cython-dev thread:  http://thread.gmane.org/gmane.comp.python.cython.devel/4769

According to William Stein, Python semantics increases the CPU time taken by approx. 20%.

Changed 4 years ago by dagss

  • priority changed from major to blocker

Robert has implemented it; all that needs doing for 0.12 is switch the default.

Changed 4 years ago by robertwb

  • status changed from new to closed
  • resolution set to fixed

Changed 4 years ago by robertwb

  • status changed from closed to reopened
  • resolution fixed deleted

Changed 4 years ago by robertwb

  • owner changed from somebody to robertwb
  • status changed from reopened to new

Changed 4 years ago by robertwb

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.