Pascal (Delphi) 中的大数
我可以使用 Delphi 中的内置方法处理大数(超过 10^400)吗?
Can I work with large numbers (more than 10^400) with built-in method in Delphi?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不是内置的,但您可能想查看 MPArith 进行任意精度数学计算。
Not built-in, but you might want to check out MPArith for arbitrary precision maths.
SourceForge 上还有一个 Delphi BigInt 库。不过,我还没有尝试过,但为了完整起见,我将其包括在内。
There is also a Delphi BigInt library on SourceForge . I haven't tried it however, but include for completeness.
您可以使用 Delphi 的运算符重载来实现您自己的大量例程。
例如加、减、乘、除。
英特尔还在不久的将来推出的最新芯片设计中添加了新的乘法指令,也可能添加了除法指令。
其中一条指令称为: mulx
英特尔提到了多个进位流,这也将允许加速乘法。
x86 已经有了带借位的减法和带进位的加法,所以现在这些新指令对于长乘法和除法等的作用或多或少相同......有两种方法可以进行乘法,并且通过使用这两种方法显然这成为可能。
将来 Delphi 可能也会支持这些新指令,这可以使编程变得更加有趣。
现在,这 4 个基本操作可能会带您到某个地方……或者可能无处可去。
这有点取决于你想做什么......什么样的数学?只是基本数学,如加/减/乘/除,
或更复杂的数学,如余弦、正弦、正切和各种其他数学功能。
据我所知,运算符重载可用于记录......我隐约记得它也可能已添加到类中,但现在对此持保留态度。
运算符重载曾经在类型之间进行转换时存在错误...但它已在更高版本的 delphi 版本中得到解决,因此应该可以继续使用。
You could implement your own large number routines using Delphi's operator overloading.
For example add, subtract, multiply and division.
Intel has also added new instructions for multiply and possibly also for division in their latest chip design to come out in the near future.
One of these instructions is called: mulx
Intel mentions multiple carry streams which would allow multiplication to be accelerated as well.
x86 already had subtract with borrow, and add with carry, so now these new instructions do more or less the same for long multiplication and division and such... there are two methods to do multiplication and by using both apperently this becomes possible.
In the future Delphi will probably support these new instructions as well which could make programming something like this extra interesting.
For now these 4 basic operations might take you somewhere... or perhaps nowhere.
It depends a bit on what you want to do.. what kind of math ? just basic math like add/sub/mul/div
Or more complex math like cosinus, sinus, tan, and all kinds of other math functionality.
As far as I know operator overloading is available for records... I can vaguely remember that it might have been added to classes as well but take a grain of salt with that for now.
Operator overloading used to have a bug when converting between types... but it's been solved in later delphi versions, so it should be good to go.