System.Numerics.BigInteger 是不可变的吗? 应该是吗?
.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信它将是不可变的(我认为他们基本上将不可变的 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.
我认为它将是不可变的,并且我认为这是“值”类型唯一合理的设计选择。 (与 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.)
它将是一成不变的。 是的,它应该是 - 否则,它的行为不会像其他数字类型一样,如果您从基于整数的代码转移到基于大整数的代码,您会看到一些非常奇怪的行为。
在未来的版本中可能应该有一个额外的可变类型(就像 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)
查看(初步但官方)文档:msdn.microsoft.com/en-us/library/system.numerics.biginteger(VS.100).aspx
Have a look at the (preliminary but official) docs at msdn.microsoft.com/en-us/library/system.numerics.biginteger(VS.100).aspx