如何在Cython中获取最大整数值?

问题描述 投票:0回答:1

我在用Cython优化一个库。在代码中,有一部分是寻找成本最小的东西。原代码看起来有点像这样。

cost = float('inf')
for thing in things:
    thing_cost = do_stuff(thing)
    if thing_cost < cost:
        cost = thing_cost

除了初始值之外,这些成本都是正整数, 所以我想把成本变成一个正整数 unsigned int. 有没有类似的东西 MAX_INT 定义在什么地方,我可以使用?

python integer cython
1个回答
2
投票

你可以用你在C语言中使用的同样的东西。limits.h.

# something.pxd
cdef extern from "limits.h":
    cdef int INT_MAX
    cdef unsigned int UINT_MAX

这些值可以在Cython中使用。

© www.soinside.com 2019 - 2024. All rights reserved.