大整数运算

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();
         }
    }
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值