Implementation limitations of float.as_integer_ratio()

后端 未结 3 631
情歌与酒
情歌与酒 2020-12-06 11:03

Recently, a correspondent mentioned float.as_integer_ratio(), new in Python 2.6, noting that typical floating point implementations are essentially rational approximations o

3条回答
  •  死守一世寂寞
    2020-12-06 12:05

    The algorithm used by as_integer_ratio only considers powers of 2 in the denominator. Here is a (probably) better algorithm.

提交回复
热议问题