BigDecimal Euler的数字计算来模拟Math.exp(double a) [英] BigDecimal Euler's number calculation to emulate Math.exp(double a)

查看:218
本文介绍了BigDecimal Euler的数字计算来模拟Math.exp(double a)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种普遍接受的方法可以在BigDecimal中获得Euler的数字吗?

Is there a generally accepted way to get Euler's number in BigDecimal?

我基本上想做Math.exp(double a)我基本上想要相同的功能但是使用BigDecimal进行计算以防止其他计算中的精度损失。

I basically want to do Math.exp(double a) and I basically want the same function but calculated using BigDecimal to prevent precision loss with other calculations.

我想到了,

BigDecimal.valueOf(Math.E).pow(BigDecimal.SOMEOTHERNUMBER)

但不确定这是否是解决问题的正确方法。

But not sure if that's the right way to approach the problem.

推荐答案

问题在于欧拉的数字是不合理的;在BigDecimal中,你必须拥有无限的内存才能拥有它。没有先前存储的值的原因是,无论你需要多少小数位,你的当前应用程序都没有正确的数字。

The problem is that Euler's number is irrational; in BigDecimal, you'd have to have infinite memory to hold it. The reason there's no previously-stored value is that however many decimal places you needed, you wouldn't have the right number for your current application.

你要去必须确定你想要多少个小数,然后使用String构造函数构造BigDecimal表示(new BigDecimal(2.71828 ...))。

You're going to have to determine how many decimals you want, then construct the BigDecimal representation using the String constructor (new BigDecimal("2.71828...")).

这篇关于BigDecimal Euler的数字计算来模拟Math.exp(double a)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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