System.Numerics.BigInteger 是不可变的吗? 应该是吗?

发布于 2024-07-17 19:18:06 字数 263 浏览 6 评论 0原文

.net Framework 4 显然将包含 BigInteger 类。 但是,我似乎无法确定它是否是不可变的。 我似乎也无法决定这是否是一件好事。

不变性有很多好处,特别是对于像大整型这样“类似价值”的东西。 另一方面,基本操作必须高效,才能使像 PowerMod 这样的高成本操作尽可能快速。 就地添加将比不可变添加更快。 我目前倾向于将不变性作为库类的更好选择(想想 String)。

有谁知道它是否是不可变的? 你认为它应该是一成不变的吗?

The .net framework 4 is apparently going to include a BigInteger class. However, I can't seem to find out whether or not it will be immutable. I also can't seem to decide whether or not that would be a good thing.

Immutability has a ton of benefits, especially for something as "value-like" as a big-int. On the other hand, the basic operations have to be efficient in order to make high-cost operations like PowerMod as speedy as possible. An inplace addition is going to be faster than an immutable addition. I'm currently leaning towards immutability as the better choice for a library class (think String).

Does anyone know if it will be immutable? Do you think it should be immutable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我家小可爱 2024-07-24 19:18:06

我相信它将是不可变的(我认为他们基本上将不可变的 DLR 实现引入了核心)。

是的,它应该是不可变的。 它的行为应该与其他数值类型(例如 Int32 和 Double)类似。 拥有一个可变的数字类会非常令人困惑。

I believe it will be immutable (I gather they are basically bringing the DLR implementation, which is immutable, into the core).

Yes, it should be immutable. It should behave like other numeric value types such as Int32 and Double. Having a mutable numeric class would be very confusing.

洛阳烟雨空心柳 2024-07-24 19:18:06

我认为它将是不可变的,并且我认为这是“值”类型唯一合理的设计选择。 (与 DLR 一样,F# BigInt 也是不可变的。很高兴我们终于在框架中获得这种类型以跨语言共享。)

I think it will be immutable, and I think this is the only reasonable design choice for a 'value' type. (Like the DLR, the F# BigInt is also immutable. It's great that we're finally getting this type in the framework to share across languages.)

一瞬间的火花 2024-07-24 19:18:06

它将是一成不变的。 是的,它应该是 - 否则,它的行为不会像其他数字类型一样,如果您从基于整数的代码转移到基于大整数的代码,您会看到一些非常奇怪的行为。

在未来的版本中可能应该有一个额外的可变类型(就像 StringBuilder 用于 String 一样)

It will be immutable. Yes, it should be -- otherwise, it won't behave like other numeric types and you will see some very strange behavior if you move from integer based code to biginteger based code.

Possibly there should be an additional mutable type in some future release (like StringBuilder is for String)

同展鸳鸯锦 2024-07-24 19:18:06

查看(初步但官方)文档:msdn.microsoft.com/en-us/library/system.numerics.biginteger(VS.100).aspx

BigInteger 类型是一种不可变类型,表示任意大的整数,理论上其值没有上限或下限。 [...] 因为 BigInteger 类型是不可变的 [...] 并且它没有上限或下限,所以任何导致 BigInteger 值变得太大的操作都可能引发 OutOfMemoryException。

Have a look at the (preliminary but official) docs at msdn.microsoft.com/en-us/library/system.numerics.biginteger(VS.100).aspx

The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds. [...] Because the BigInteger type is immutable [...] and because it has no upper or lower bounds, an OutOfMemoryException can be thrown for any operation that causes a BigInteger value to grow too large.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文