Skip to content

[ENH] Speed up bool() with C arguments #7015

@user202729

Description

@user202729

Is your feature request related to a problem? Please describe.

Consider the following code

cpdef bint f(long x):
	return bool(x)

this correctly returns True if x ≠ 0 and False otherwise, but needs to pass to Python.

On the other hand, this

cpdef bint f(long x):
	return x

incorrectly returns False for 2**32.

Describe the solution you'd like.

Optimize the former.

Describe alternatives you've considered.

Currently return x != 0 works.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions