F# 中 BigInteger 中的 Pow 有替代品吗?
当我的编译器告诉我时,我正在使用 F# 中 BigInteger 类的 Pow 函数:
此构造已弃用。该成员已被删除,以确保该成员 类型与 .NET 4.0 类型 System.Numerics.BigInteger 二进制兼容
我想这很公平,但我没有立即找到替代品。
有吗?我们应该只使用我们自己的 Pow 函数吗?以及(如何)在NET4.0中会被取代?
I was using the Pow function of the BigInteger class in F# when my compiler told me :
This construct is deprecated. This member has been removed to ensure that this
type is binary compatible with the .NET 4.0 type System.Numerics.BigInteger
Fair enough I guess, but I didn't found a replacement immediately.
Is there one? Should we only use our own Pow functions? And (how) will it be replaced in NET4.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 pown 函数
let result = pown 42I 42
pown 适用于任何“理解”乘法和“一”的类型。
You can use the pown function
let result = pown 42I 42
pown works on any type that 'understands' multiplication and 'one'.
如果你从基于 OCaml 的角度来看待 F#,那么 OCaml Num 模块 有 power_num。由于 OCaml 类型 num 是任意精度的有理数,因此它们可以处理任何大小的数字,例如,它们不受 CPU 寄存器的限制,因为它们可以以符号方式进行数学运算。另外,由于 num 被定义为
类型 num =
|整数的整数
| Big_int 的 Big_int.big_int
| Ratio.ratio 的比率
由于 Ratio 类型,它们可以处理非常小的数字而不会损失精度。
由于 F# 没有 num 类型,Jack 创建了 FSharp.Compatibility.OCaml 模块,其中具有 num.fs 可通过 NuGet 获取。
因此,您可以使用它获得所需的所有精度,并且 num 函数可以处理负指数。
If you look at F# from the perspective of being based on OCaml, then the OCaml Num module has power_num. Since OCaml type num are arbitrary-precision rational numbers they can handle any size number, e.g. they are not limited by the CPU register because they can do the math symbolically. Also since num is defined as
type num =
| Int of int
| Big_int of Big_int.big_int
| Ratio of Ratio.ratio
they can handle very small numbers with out loss of precision because of the Ratio type.
Since F# does not have the num type, Jack created the FSharp.Compatibility.OCaml module which has num.fs and is available via NuGet.
So you can get all the precision you want using this, and the num functions can handle negative exponents.