狮身人面像浮点格式化 [英] Sphinx floating point formatting
问题描述
例如,如果我有以下功能:
$ $ p $ def f (x = 0.97):
return x + 1
生成的文档看起来像:
foo(x = 0.96999999999997)
显然这是一个浮点精度问题,但是有没有办法使文档看起来不那么难看?
.. autofunction ::
指令覆盖函数签名。因此,为了解决你的例子,在模块 bar
中定义为 foo(x = 0.97)
的函数: .. automodule :: bar
.. autofunction :: foo(x = 0.97)
结果文档将使用提供的签名而不是解释版本,
$ b
你可以用 .. autoclass ::
和。automethod :: $ c $等等。这是在狮身人面像这部分中的选项和高级用法中记录的用法。 ext.autodoc docs。
I'm using Sphinx to generate documentation from code. Does anyone know if there is a way to control the formatting of floating point numbers generated from default arguments.
For example if I have the following function:
def f(x = 0.97):
return x+1
The generated documentation ends up looking like:
foo(x = 0.96999999999997)
Obviously this is a floating point precision issue, but is there a way to make the documentation not look so ugly?
You can override a function signature with the .. autofunction::
directive. So to address your example, a function defined as foo(x=0.97)
in module bar
:
.. automodule:: bar
.. autofunction:: foo(x=0.97)
And the resulting doc will use the signature provided instead of the interpreted version with the really long number.
You can do this equivalently with .. autoclass::
and .. automethod::
and the like. This is usage is documented in "Options and advanced usage" in this part of the sphinx.ext.autodoc docs.
这篇关于狮身人面像浮点格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!