如何处理javascript中的大数字 [英] How to deal with big numbers in javascript

查看:61
本文介绍了如何处理javascript中的大数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个处理真正(长、大、巨大、风暴)数字的数学解决方案.我还没有找到任何东西,但我不想认为这个问题目前还没有解决.我正在寻找一个简单的数字解决方案,例如 Microsoft Excel Precision(30 位小数)或 BigInteger (Java) 解决方案.当然是在 Javascript 中.

I'm looking for a Mathematical solution that deals with really (long, big, huge, storms) numbers. I haven't found anything yet, But I don't wanna think that this problem hasn't be solve at this time. I'm looking for an easy Number solution, like Microsoft Excel Precision (30 decimals), or a BigInteger (Java) solution. in Javascript of course.

推荐答案

在为 ElGamal 加密实现寻找大整数库时,我测试了几个库,结果如下:

While looking for an big integer library for an ElGamal crypto implementation I tested several libraries with the following results:

我推荐这个: Tom Wu 的 jsbn.js (http://www-cs-students.stanford.edu/~tjw/jsbn/)

I recommend this one: Tom Wu's jsbn.js (http://www-cs-students.stanford.edu/~tjw/jsbn/)

  • 功能全面,速度快

Leemon Baird 的大整数库(http://www.leemon.com/crypto/BigInt.js)

  • 功能全面,速度相当快
  • 但是:负数表示是错误的!
  • Comprehensive set of functions and pretty fast
  • BUT: Negative number representation is buggy!

bignumber.js (https://github.com/MikeMcl/bignumber.js)

  • 相当完整的功能集
  • 但是:将非常大的数字从字符串转换为 BigNumber 对象会导致 INFINITY
  • Pretty complete set of functions
  • BUT: Converting really big numbers from strings into BigNumber objects result in INFINITY

用于 JavaScript 的方案算术库 (https://github.com/jtobey/javascript-bignum)

  • JS-Scheme算术函数的实现
  • 但是: y= x^e mod n 没有函数
  • JS-Implementation of Scheme arithmetic functions
  • BUT: No function for y= x^e mod n

我自己没有测试过这个: BigNumber (http:///jsfromhell.com/classes/bignumber)

I haven't tested this by myself: BigNumber (http://jsfromhell.com/classes/bignumber)

  • 高精度计算函数
  • 但是:据说速度很慢,因为数字内部表示为字符串
  • Functions for high precision claculations
  • BUT: It's said to be slow due to internal representation of numbers as strings

这篇关于如何处理javascript中的大数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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