Java浮点高精度库 [英] Java floating point high precision library

查看:132
本文介绍了Java浮点高精度库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪些Java库适合浮点运算或定点运算,精度高达数千位?性能如何?



对我的一个要求是,它实现了一个乘法算法,它比原来的乘法算法要好4倍的时间2次更多数字(比较乘法算法)。

任意精度算术中提到了三个库, / a>页面:java.math(包含提到的BigDecimal), Apfloat JScience 。我运行一些速度检查他们只是使用加法和乘法。

结果是,对于一个相对较少的数字BigDecimal是可以的(一半的速度比其他的1000位数),但是如果你使用更多的数字,关 - JScience快了4倍。但明显的表现赢家是Apfloat。其他库似乎使用天真的乘法算法,其时间与数位的平方成正比,但Apfloat的时间似乎几乎线性增长。在10000位数字上,它是JScience的4倍,但在40000位数字上是JScience的16倍。另一方面:JScience提供了EXCELLENT功能数学问题:矩阵,向量,符号算法,方程系统的解决方案,还有什么不是。所以我可能会和JScience一起,后来编写一个包装器来将Apfloat集成到JScience的算法中 - 由于这个好的设计,这看起来很容易。
$ b

(UPDATE:我为JScience的数字包编写了一个测试套件,并修复了一些bug,这个版本进入了4.3.1版本,所以我可以推荐检查一下。)


Which libraries for Java are there that have a fast implementation for floating point or fixed point operations with a precision of several thousands of digits? How performant are they?

A requirement for me is that it implements a multiplication algorithm that is better than the naive multiplication algorithm that takes 4 times as much time for a 2 times larger number of digits (compare Multiplication algorithms).

解决方案

There are three libraries mentioned on the Arbitrary Precision Arithmetic page: java.math (containing the mentioned BigDecimal), Apfloat and JScience. I run a little speed check on them which just uses addition and multiplication.

The result is that for a relatively small number of digits BigDecimal is OK (half as fast as the others for 1000 digits), but if you use more digits it is way off - JScience is about 4 times faster. But the clear performance winner is Apfloat. The other libraries seem to use naive multiplication algorithms that take time proportional to the square of the number of digits, but the time of Apfloat seems to grow almost linearly. On 10000 digits it was 4 times as fast as JScience, but on 40000 digits it is 16 times as fast as JScience.

On the other hand: JScience provides EXCELLENT functionality for mathematical problems: matrices, vectors, symbolic algorithms, solution of equation systems and what not. So I'll probably go with JScience and later write a wrapper to integrate Apfloat into the algorithms of JScience - due to the good design this seems easily possible.

(UPDATE: I wrote a test suite for the number package of JScience and fixed a number of bugs. This went into release 4.3.1. So I can recommend checking it out.)

这篇关于Java浮点高精度库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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