Perl 6 性能是否因使用十进制数的有理数而受到影响 [英] Does Perl 6 performance suffer by using rationals for decimal numbers

查看:81
本文介绍了Perl 6 性能是否因使用十进制数的有理数而受到影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解 Perl 6 尽可能将小数实现为有理数,以避免大多数其他语言中存在的浮点问题.

I understand that Perl 6 implements decimals as rationals wherever possible in order to avoid floating point issues that are present in most other languages.

是否有人做过基准测试或了解这样做的性能损失?

Has anybody done benchmarking or have an understanding of the performance penalty of doing this?

推荐答案

Perl 6 性能是否因使用十进制数的有理数而受到影响

Does Perl 6 performance suffer by using rationals for decimal numbers

我认为最有用的总体答案是不,不是真的,但让我详细说明一下".

I think the most useful overall answer is "no, not really, but let me elaborate a bit".

如果您希望 P6 自动保持十进制计算相当准确和快速,那么只需使用 大鼠s.

If you'd like P6 to just automatically keep decimal calculations reasonably accurate and fast, then just use Rats.

如果计算涉及一个或多个 P6 Rats 的表达式的总结果的分母溢出 64 位,则 P6 会自动将结果转换为近似 Num(P6 对 double float) 以保持合理的性能.

If the denominator of the overall result of computing an expression involving one or more P6 Rats overflows 64 bit then P6 will automatically switch the result to an approximate Num (P6's implementation of a double float) to maintain reasonable performance.

您可以直接对小数使用浮点数据类型.

You can directly use a floating point data type for decimals.

这会产生通常比合理性能更快的浮点性能.

This yields floating point performance which is generally faster than rational performance.

例如,3.141592e0 不是有理数/十进制文字,而是 Num/float 文字.

For example, 3.141592e0 is not a rational/decimal literal but instead a Num/float literal.

如果您使用一种内置的有理数据类型(有限精度 Rat 类;任意精度 FatRat;或底层参数化精度Rational 角色)然后如果计算适合分母,则对该数据的数字运算将是 100% 准确的.

If you use one of the built in rational data types (the limited precision Rat class; the arbitrary precision FatRat class; or the underlying parameterizable precision Rational role) then numeric operations on that data will be 100% accurate if the calculation fits in the denominator.

阅读有关有理数据类型的维基百科页面,以作为了解使用有理类型.

Read the wikipedia page on rational data types for a starting point on understanding the performance implications of using a rational type.

是否有人做过基准测试或了解这样做的性能损失?

Has anybody done benchmarking or have an understanding of the performance penalty of doing this?

Larry Wall 做出的设计决定导致小数在默认情况下被处理为有理数.他讨论了#perl6 上的性能影响.一些有用的搜索:

Larry Wall made the design decisions that led to decimals being, by default, processed as rationals. He has discussed the performance implications on #perl6. Some useful searches:

'理性'

'float'

'分母'

如果我找到有用的基准测试的链接,我会稍后添加它们.

If I find links to useful benchmarks I'll add them later.

这篇关于Perl 6 性能是否因使用十进制数的有理数而受到影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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