【原创】开源Math.NET基础数学类库使用(09)相关数论函数使用

本文介绍了开源Math.NET基础数学类库中的数论函数,包括Euclid类及其使用,如判断奇偶性、最大公约数等,并提供了使用示例。通过学习,开发者可以更好地理解和应用这些数论函数。
摘要由CSDN通过智能技术生成
               本博客所有文章分类的总目录:【总目录】本博客博文总目录-实时更新 

开源Math.NET基础数学类库使用总目录:【目录】开源Math.NET基础数学类库使用总目录

前言

  数论就是指研究整数性质的一门理论。数论=算术。不过通常算术指数的计算,数论指数的理论。整数的基本元素是素数,所以数论的本质是对素数性质的研究。它是与平面几何同样历史悠久的学科。它大致包括代数数论、解析数论、计算数论等等。

  Math.NET也包括了很多数论相关的函数,这些函数都是静态的,可以直接调用,如判断是否奇数,判断幂,平方数,最大公约数等等。同时部分函数已经作为扩展方法,可以直接在对象中使用。

  如果本文资源或者显示有问题,请参考 本文原文地址http://www.cnblogs.com/asxinyu/p/4301097.html 

1.数论函数类Euclid

  Math.NET包括的数论函数除了一部分大家日常接触到的,奇数,偶数,幂,平方数,最大公约数,最小公倍数等函数,还有一些欧几里得几何的函数,当然也是比较简单的,这些问题的算法有一些比较简单,如最大公约数,最小公倍数等,都有成熟的算法可以使用,对于使用Math.NET的人来说,不必要了解太小,当然对于需要搞清楚原理的人来说,学习Math.NET的架构或者实现,是可以参考的。所以这里先给出Math.NET关于数论函数类Euclid的源代码:

  1 /// <summary>
  2 /// 整数数论函数
  3 /// Integer number theory functions.
  4 /// </summary>
  5 public static class Euclid
  6 {
  7     /// <summary>
  8     /// Canonical Modulus. The result has the sign of the divisor.
  9     /// </summary>
 10     public static double Modulus(double dividend, double divisor)
 11     {
 12         return ((dividend%divisor) + divisor)%divisor;
 13     }
 14 
 15     /// <summary>
 16     /// Canonical Modulus. The result has the sign of the divisor.
 17     /// </summary>
 18     public static float Modulus(float dividend, float divisor)
 19     {
 20         return ((dividend%divisor) + divisor)%divisor;
 21     }
 22 
 23     /// <summary>
 24     /// Canonical Modulus. The result has the sign of the divisor.
 25     /// </summary>
 26     public static int Modulus(int dividend, int divisor)
 27     {
 28         return ((dividend%divisor) + divisor)%divisor;
 29     }
 30 
 31     /// <summary>
 32     /// Canonical Modulus. The result has the sign of the divisor.
 33     /// </summary>
 34     public static long Modulus(long dividend, long divisor)
 35     {
 36         return ((dividend%divisor) + divisor)%divisor;
 37     }
 38 
 39 #if !NOSYSNUMERICS
 40     /// <summary>
 41     /// Canonical Modulus. The result has the sign of the divisor.
 42     /// </summary>
 43     public static BigInteger Modulus(BigInteger dividend, BigInteger divisor)
 44     {
 45         return ((dividend%divisor) + divisor)%divisor;
 46     }
 47 #endif
 48 
 49     /// <summary>
 50     /// Remainder (% operator). The result has the sign of the dividend.
 51     /// </summary>
 52     public static double Remainder(double dividend, double divisor)
 53     {
 54         return dividend%divisor;
 55     }
 56 
 57     /// <summary>
 58     /// Remainder (% operator). The result has the sign of the dividend.
 59     /// </summary>
 60     public static float Remainder(float dividend, float divisor)
 61     {
 62         return dividend%divisor;
 63     }
 64 
 65     /// <summary>
 66     /// Remainder (% operator). The result has the sign of the dividend.
 67     /// </summary>
 68     public static int Remainder(int dividend, int divisor)
 69     {
 70         return dividend%divisor;
 71     }
 72 
 73     /// <summary>
 74     /// Remainder (% operator). The result has the sign of the dividend.
 75     /// </summary>
 76     public static long Remainder(long dividend, long divisor)
 77     {
 78         return dividend%divisor;
 79     }
 80 
 81 #if !NOSYSNUMERICS
 82     /// <summary>
 83     /// Remainder (% operator). The result has the sign of the dividend.
 84     /// </summary>
 85     public static BigInteger Remainder(BigInteger dividend, BigInteger divisor)
 86     {
 87         return dividend%divisor;
 88     }
 89 #endif
 90 
 91     /// <summary>
 92     /// Find out whether the provided 32 bit integer is an even number.
 93     /// </summary>
 94     /// <param name="number">The number to very whether it's even.</param>
 95     /// <returns>True if and only if it is an even number.</returns>
 96     public static bool IsEven(this int number)
 97     {
 98         return (number & 0x1) == 0x0;
 99     }
100 
101     /// <summary>
102     /// Find out whether the provided 64 bit integer is an even number.
103     /// </summary>
104     /// <param name="number">The number to very whether it's even.</param>
105     /// <returns>True if and only if it is an even number.</returns>
106     public static bool IsEven(this long number)
107     {
108         return (number & 0x1) == 0x0;
109     }
110 
111     /// <summary>
112     /// Find out whether the provided 32 bit integer is an odd number.
113     /// </summary>
114     /// <param name="number">The number to very whether it's odd.</param>
115     /// <returns>True if and only if it is an odd number.</returns>
116     public static bool IsOdd(this int number)
117     {
118         return (number & 0x1) == 0x1;
119     }
120 
121     /// <summary>
122     /// Find out whether the provided 64 bit integer is an odd number.
123     /// </summary>
124     /// <param name="number">The number to very whether it's odd.</param>
125     /// <returns>True if and only if it is an odd number.</returns>
126     public static bool IsOdd(this long number)
127     {
128         return (number & 0x1) == 0x1;
129     }
130 
131     /// <summary>
132     /// Find out whether the provided 32 bit integer is a perfect power of two.
133     /// </summary>
134     /// <param name="number">The number to very whether it's a power of two.</param>
135     <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值