Opened 7 years ago

Closed 6 months ago

#259 closed defect (fixed)

future division not respected by C ints (including literals)

Reported by: robertwb Owned by: somebody
Priority: major Milestone: wishlist
Component: Python Semantics Keywords:
Cc: haoyu

Description (last modified by dagss)


from __future__ import division # or, cython3

cdef int a, b = 1, c = 2
a = b / c

should result in a compilation error. The resulting type of / with future division should be some floating point regardless of whether the input types are int.

In the generated code, this means the arguments (b and c above) must be cast to float prior to the division.

Attachments (1)

division_cint.patch (1.2 KB) - added by haoyu 5 years ago.
Test cases

Download all attachments as: .zip

Change History (6)

comment:1 follow-up: Changed 6 years ago by haoyu

  • Cc haoyu added

Could you elaborate this? Any test case?

comment:2 in reply to: ↑ 1 Changed 6 years ago by dagss

  • Description modified (diff)

Replying to haoyu:

Could you elaborate this? Any test case?

comment:3 Changed 6 years ago by dagss

Hmm. It appears I modified the description instead of replying...But it fits this way as well. See the new description for a reply.

comment:4 Changed 5 years ago by haoyu

It seems this is already implemented. The example will raise an error "Cannot assign type 'double' to 'int'".

I just added some test cases. See the attached patch.

Changed 5 years ago by haoyu

Test cases

comment:5 Changed 6 months ago by scoder

  • Component changed from Code Generation to Python Semantics
  • Resolution set to fixed
  • Status changed from new to closed

Fixed long ago.

Note: See TracTickets for help on using tickets.