Skip to content

Exponentiation of integer constants interpreted as integer #2133

@timostrunk

Description

@timostrunk

Problem

When specifying numeric constants with the unusual syntax:
10 ** -1
cython most probably inteprets the result as integer, while the python interpreter interprets it as float.
This only affects constants and does not affect variables.

Minimal Example

Code

test.pyx / test.py

print (10 ** -1)
print (1E-1)
a = 10
print (a ** -1)

setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("test.pyx")
)

Compilation

python ./setup.py build_ext --inplace

Results

python -c "import test" # with uncompiled test.py

0.1
0.1
0.1

python -c "import test" # with compiled test.pyx

0
0.1
0.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions