special floats generate incorrect C code when used as compile-time constants

Bug #218377 reported by Jacques Frechet
2
Affects Status Importance Assigned to Milestone
Cython
Fix Committed
Medium
Unassigned

Bug Description

For example:

  DEF INFINITY = float('inf')
  print INFINITY

results in:

  foo.c: In function ‘init2foo’:
  foo.c:158: error: ‘inf’ undeclared (first use in this function)
  foo.c:158: error: (Each undeclared identifier is reported only once
  foo.c:158: error: for each function it appears in.)

I get the same error message with -inf and a somewhat different error message with nan (since math.h defines a function by that name).

In the meantime, I'll do this instead:

  cdef extern from "math.h":
    double INFINITY, NAN

Revision history for this message
scoder (scoder) wrote :

Fixed in cython-devel. Thanks!

Changed in cython:
importance: Undecided → Medium
status: New → Fix Committed
Revision history for this message
Christian Heimes (heimes) wrote :

I recommend against using the constants from math.h. Python has some helpers in pyport.h (or pymath.h starting with 2.6):

inf = Py_HUGE_VAL
-inf = -Py_HUGE_VAL
nan = Py_HUGE_VAL * 0.

Revision history for this message
scoder (scoder) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.