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.
.net框架4显然将包含一个BigInteger类。但是,我似乎无法弄清楚它是否会一成不变。我似乎也无法决定这是否是一件好事。
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).
不变性有很多好处,特别是对于像“大型”这样“像价值一样”的东西。另一方面,基本操作必须是高效的,以便尽可能快地使像PowerMod这样的高成本操作。原地添加比不可变添加更快。我目前倾向于不变性作为库类的更好选择(想想String)。
Does anyone know if it will be immutable? Do you think it should be immutable?
有谁知道它是否会一成不变?你认为它应该是不可改变的吗?
4 个解决方案
#1
I believe it will be immutable (I gather they are basically bringing the DLR implementation, which is immutable, into the core).
我相信它将是不可变的(我认为它们基本上将DLR实现,它是不可变的,进入核心)。
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.
是的,它应该是不可改变的。它的行为应该像其他数值类型,如Int32和Double。拥有一个可变数字类会非常混乱。
#2
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.)
我认为这是不可改变的,我认为这是“价值”类型唯一合理的设计选择。 (就像DLR一样,F#BigInt也是不可变的。很高兴我们终于在框架中获得这种类型以跨语言共享。)
#3
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.
这将是不可改变的。是的,它应该是 - 否则,它将不会像其他数字类型一样,如果您从基于整数的代码转移到基于biginteger的代码,您将看到一些非常奇怪的行为。
Possibly there should be an additional mutable type in some future release (like StringBuilder is for String)
可能在将来的某个版本中应该有一个额外的可变类型(比如StringBuilder用于String)
#4
Have a look at the (preliminary but official) docs at msdn.microsoft.com/en-us/library/system.numerics.biginteger(VS.100).aspx
在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.
BigInteger类型是一个不可变类型,表示一个任意大的整数,其理论上的值没有上限或下限。 [...]因为BigInteger类型是不可变的[...]并且因为它没有上限或下限,所以可以为任何导致BigInteger值过大的操作抛出OutOfMemoryException。
#1
I believe it will be immutable (I gather they are basically bringing the DLR implementation, which is immutable, into the core).
我相信它将是不可变的(我认为它们基本上将DLR实现,它是不可变的,进入核心)。
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.
是的,它应该是不可改变的。它的行为应该像其他数值类型,如Int32和Double。拥有一个可变数字类会非常混乱。
#2
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.)
我认为这是不可改变的,我认为这是“价值”类型唯一合理的设计选择。 (就像DLR一样,F#BigInt也是不可变的。很高兴我们终于在框架中获得这种类型以跨语言共享。)
#3
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.
这将是不可改变的。是的,它应该是 - 否则,它将不会像其他数字类型一样,如果您从基于整数的代码转移到基于biginteger的代码,您将看到一些非常奇怪的行为。
Possibly there should be an additional mutable type in some future release (like StringBuilder is for String)
可能在将来的某个版本中应该有一个额外的可变类型(比如StringBuilder用于String)
#4
Have a look at the (preliminary but official) docs at msdn.microsoft.com/en-us/library/system.numerics.biginteger(VS.100).aspx
在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.
BigInteger类型是一个不可变类型,表示一个任意大的整数,其理论上的值没有上限或下限。 [...]因为BigInteger类型是不可变的[...]并且因为它没有上限或下限,所以可以为任何导致BigInteger值过大的操作抛出OutOfMemoryException。