GO/Golang:如何从Big.Float中提取最小的数字?
在GO/Golang中,我有一个类型Big.Float的变量,(任意)精度为3,324,000,代表十进制数字的1,000,000位数字。这是计算PI的迭代的结果。 现在,我想打印出最小的100位数字,即数字999,900至1,000,000。
我尝试使用FMT.sprintf()和big.text()将变量转换为字符串。但是,两种功能都会在进一步提高精度时消耗大量的处理时间,这些处理时间变得不可接受(很多小时甚至几天)。
我正在寻找一些提取变量的最后100个(十进制)数字的功能。 事先感谢您的支持。
In Go/Golang I have a variable of type big.Float with an (arbitrary) precision of 3,324,000 to represent a decimal number of 1,000,000 digits. It's the result of an iteration to calculate pi.
Now I want to print out the least significant 100 digits, i.e. digits 999,900 to 1,000,000.
I tried to convert the variable to a string by using fmt.Sprintf() and big.Text(). However, both functions consume a lot of processing time which gets unacceptable (many hours and even days) when further raising the precision.
I'm searching for some functions which extract the last 100 (decimal) digits of the variable.
Thanks in advance for your kind support.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标准库无法提供有效返回这些数字的函数,但是您可以计算它们。
隔离您感兴趣的数字并打印它们更有效。这避免了过多的计算,以确定每个数字。
下面的代码显示了可以完成的方法。您将需要确保有足够的精度来准确生成它们。
The standard library doesn't provide a function to return those digits efficiently, but you can calculate them.
It is more efficient to isolate the digits you are interested in and print them. This avoids excessive calculations of an extremely large number to determine each individual digit.
The code below shows a way it can be done. You will need to ensure you have enough precision to generate them accurately.