本博客所有文章分类的总目录:【总目录】本博客博文总目录-实时更新
开源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 <