log2 in python math module

后端 未结 2 1532
甜味超标
甜味超标 2021-02-05 00:22

why doesn\'t it exist?

import math
[x for x in dir(math) if \'log\' in x]
>>> [\'log\', \'log10\', \'log1p\']

I know I can do log(x,2)

2条回答
  •  说谎
    说谎 (楼主)
    2021-02-05 00:31

    I'm not sure that there is that you want, but:

    -- From math point of view you can do for example math.log(x)/math.log(2).

    -- If input X has an integral type and you are waiting for the integral rounded result - you can do it rather faster with right shifting. This works with SHR command and without Taylor series + local interpolation, which is under the hood of libc log() calls.

提交回复
热议问题