如何使用python模块gmpy2

时间:2018-06-20 14:52:02

标签: python gmpy

我创建了以下python代码。首先应该将数字的精度设置为10个十进制数字,但是打印pi会显示3.156,其中只有3个十进制数字!有人可以让我知道我在做什么错。

import gmpy2 as g
from ipywidgets import widgets
from IPython.display import display

button = widgets.Button(description="Click Me!")
display(button)

max_precision = g.get_max_precision()
pi = g.const_pi()
g.set_context(g.context())

def set_bits_precision(decimal_precision):
    bits_precision = int(decimal_precision/g.log(2))
    if (bits_precision > max_precision): bits_precision = max_precision
    ctx = g.get_context()
    ctx.precision = bits_precision
    return

def square_root(number):
    return g.sqrt(number)

def circle_perimeter(radius):
    return 2*pi*radius 

def on_button_clicked(x):
    return square_root(x)

set_bits_precision(10)
print(pi)
button.on_click(on_button_clicked(2))

0 个答案:

没有答案