Opened 6 years ago

Last modified 4 years ago

#259 new defect

future division not respected by C ints (including literals)

Reported by: robertwb Owned by: somebody
Priority: major Milestone: wishlist
Component: Code Generation Keywords:
Cc: haoyu

Description (last modified by dagss)

This:

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 4 years ago.
Test cases

Download all attachments as: .zip

Change History (5)

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

  • Cc haoyu added

Could you elaborate this? Any test case?

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

  • Description modified (diff)

Replying to haoyu:

Could you elaborate this? Any test case?

comment:3 Changed 5 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 4 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 4 years ago by haoyu

Test cases

Note: See TracTickets for help on using tickets.