using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Runtime.InteropServices;
namespace MyBigInteger
{
/*
* 工具->生成GUID
* 项目->属性->生成->为COM互操作注册
* regasm MyLib.dll
*在SQL中调用
Declare @App int
Declare @sOutText Varchar(8000)
Exec sp_OACreate 'MyBigInteger.MyClass', @App OUT
Exec sp_OAMethod @App, 'BigPow',@sOutText out,2,3000
Exec sp_OADestroy @App
Select @sOutText
Exec sp_OAStop
*在Excel中调用
Dim obj As Object
Set obj = CreateObject("MyBigInteger.MyClass")
x = obj.BigPow(2, 3000)
Set x = Nothing
*/
[ComVisible(true)]
[Guid("03A397E0-950D-471C-A8C1-96A100BB3C79")]
public interface IMyClass
{
void Initialize();
void Dispose();
string BigAdd(string x, string y);
}
[ComVisible(true)]
[Guid("D9830F37-83BB-4885-904F-FBFEB93EE85F")]
[ProgId("MyBigInteger.MyClass")]
public class MyClass : IMyClass
{
public void Initialize()
{
}
public void Dispose()
{
}
public string BigAbs(string x)
{
//绝对值
BigInteger x1 = BigInteger.Parse(x);
return BigInteger.Abs(x1).ToString();
}
public string BigAdd(string x, string y)
{
//加法
BigInteger x1 = BigInteger.Parse(x);
BigInteger y1 = BigInteger.Parse(y);
return BigInteger.Add(x1, y1).ToString();
}
public int BigCompare(string x, string y)
{
//比较大小
BigInteger x1 = BigInteger.Parse(x);
BigInteger y1 = BigInteger.Parse(y);
return BigInteger.Compare(x1, y1);
}
public string BigDivide(string x, string y)
{
//除法
BigInteger x1 = BigInteger.Parse(x);
BigInteger y1 = BigInteger.Parse(y);
return BigInteger.Divide(x1, y1).ToString();
}
public string BigGreatestCommonDivisor(string x, string y)
{
//最大公约数
BigInteger x1 = BigInteger.Parse(x);
BigInteger y1 = BigInteger.Parse(y);
return BigInteger.GreatestCommonDivisor(x1, y1).ToString();
}
public string BigLog(string x, double y)
{
//指定底数的对数
BigInteger x1 = BigInteger.Parse(x);
return BigInteger.Log(x1, y).ToString();
}
public string BigLog10(string x)
{
//10为底数的对数
BigInteger x1 = BigInteger.Parse(x);
return BigInteger.Log10(x1).ToString();
}
public string BigMax(string x,string y)
{
//最大值
BigInteger x1 = BigInteger.Parse(x);
BigInteger y1 = BigInteger.Parse(y);
return BigInteger.Max(x1, y1).ToString();
}
public string BigMin(string x, string y)
{
//最小值
BigInteger x1 = BigInteger.Parse(x);
BigInteger y1 = BigInteger.Parse(y);
return BigInteger.Min(x1, y1).ToString();
}
public string BigMultiply(string x, string y)
{
//乘法
BigInteger x1 = BigInteger.Parse(x);
BigInteger y1 = BigInteger.Parse(y);
return BigInteger.Multiply(x1, y1).ToString();
}
public string BigNegate(string x)
{
//求反
BigInteger x1 = BigInteger.Parse(x);
return BigInteger.Negate(x1).ToString();
}
public string BigPow(string x,int y)
{
//求幂
BigInteger x1 = BigInteger.Parse(x);
return BigInteger.Pow(x1,y).ToString();
}
public string BigRemainder(string x, string y)
{
//求余
BigInteger x1 = BigInteger.Parse(x);
BigInteger y1 = BigInteger.Parse(y);
return BigInteger.Remainder(x1, y1).ToString();
}
public string BigSubtract(string x, string y)
{
//减法
BigInteger x1 = BigInteger.Parse(x);
BigInteger y1 = BigInteger.Parse(y);
return BigInteger.Subtract(x1, y1).ToString();
}
}
}