使用对数而不是大数除法? [英] Using logarithm instead of division for large numbers?

查看:87
本文介绍了使用对数而不是大数除法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不能为我的问题想出一个恰当的标题,但允许我陈述自己的情况;我想计算以下形式的显着性比率:p = 1- X / Y

I couldn't really come up with a proper title for my question but allow me to present my case; I want to calculate a significance ratio in the form: p = 1 - X / Y

X 来自一个迭代过程;该过程需要大量步骤,并计算出该过程可以以多种不同方式最终以不同状态(存储在HashMap中)进行计数.迭代结束后,我将选择多个状态并求和它们的值.很难说出这些数字有多大,所以我打算将总和实现为BigInteger.

Here X comes from an iterative process; the process takes a large number of steps and counts how many different ways the process can end up in different states (stored in a HashMap). Once the iteration is over, I select a number of states and sum their values. It's hard to tell how large these numbers are so I am intending to implement the sum as BigInteger.

Y 来自具有成千上万个数字的二项式系数.我倾向于使用logGamma来计算这些系数,结果使我得到了该值的自然对数.

Y, on the other hand comes from a binomial coefficient with numbers in thousands-scale. I am inclined to use logGamma to calculate these coefficients, which as a result give me the natural logarithm of the value.

我感兴趣的是以最佳/最有效的方式进行 X / Y 除法.如果我可以在自然对数中得到 X ,那么我可以减去幂,结果为1-e ^(lnX-lnY).

What I am interested in is to do division X / Y in the best/most effective way. If I can get X in the natural logarithm then I could subtract the powers and have my result as 1 - e ^ (lnX - lnY).

我看到BigInteger不能被Math.log对数,在这种情况下我该怎么办?

I see that BigInteger can't be logarithmized by Math.log, what can I do in this case?

推荐答案

您可能可以使用双打.双精度可能非常大,约为1.7e308.它缺少的是精度:它仅支持约15位数字.但是,如果您能够以15位数的精度生活(换句话说,如果您不关心1,000,000,000,000,000和1,000,000,000,000,001之间的差异),那么加倍可能使您足够接近.

You may be able to use doubles. A double can be extremely large, about 1.7e308. What it lacks is precision: it only supports about 15 digits. But if you can live with 15 digits of precision (in other words, if you don't care about the difference between 1,000,000,000,000,000 and 1,000,000,000,000,001) then doubles might get you close enough.

这篇关于使用对数而不是大数除法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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