【发布时间】:2015-04-18 19:56:02
【问题描述】:
我正在尝试将开源库从 .Net 4.0 转换为 3.5,但无法轻松转换以下长乘法代码:
/// <summary>
/// Calculate the most significant 64 bits of the 128-bit
product x * y, where x and y are 64-bit integers.
/// </summary>
/// <returns>Returns the most significant 64 bits of the product x * y.</returns>
public static long mul64hi(long x, long y)
{
#if !NET35
BigInteger product = BigInteger.Multiply(x, y);
product = product >> 64;
long l = (long)product;
return l;
#else
throw new NotSupportedException(); //TODO!
#endif
}
如您所见,作者没有找到方法来做到这一点。 BigInteger 在 .NET 3.5 中不存在。
如何在 .NET 3.5 上计算 64*64 乘法的高位 64 位?
【问题讨论】:
-
感谢您提供的链接,使用 J# 库我可能会使其工作!我现在正在尝试...
-
hm 不适合我,MDSN 说它仅适用于 VS 5 或更低版本,我需要使用 VS2010 解决其他问题(默认参数)
-
由于您要求的是一个众所周知的问题(高位乘法),因此存在现有解决方案:stackoverflow.com/questions/28868367/… 我没有找到 C# 解决方案,但 C 代码应该可以按原样工作。
-
@usr 谢谢,我会看看那个,目前正在遵循一个解决方案,该解决方案使用 Mono 源代码中的 System.Numeric 命名空间Answer 它看起来很有希望:)跨度>
标签: c# .net biginteger multiplication