如何在python中存储大于1 * 10 ^ 310的浮点数? [英] How can I store float numbers larger than 1*10^310 in python?

查看:64
本文介绍了如何在python中存储大于1 * 10 ^ 310的浮点数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个输出大矩阵的条件数的程序,因此我使用了幂方法来获得最大特征值,但是这些值是大于1 * 10 ^ 310的大数(浮点数),并且最后值变成无穷大",我尝试了十进制模块,但它是相同的.如何存储那些较大的浮点值?还是另一种使用较短值的方法?(我不允许使用任何将过程明确地帮助为Numpy的模块)

I am working on a program that outputs the condition number of a big matrix, so I used the Power Method to get the Largest EigenValue, but the values are large numbers (float) larger than 1*10^310, and in the end the values become "Infinity", I tried the decimal module but it's the same. How can I store those large float values? Or maybe another method that uses shorter values? (I'm not allowed to use any module that helps explicitly the proccess as Numpy)

推荐答案

您要使用十进制模块:

from decimal import Decimal

x = Decimal('1.345e1310')
y = Decimal('1.0e1310')
print(x + y)

结果:

2.345E+1310

这篇关于如何在python中存储大于1 * 10 ^ 310的浮点数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆