Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../stdafx.h"
00013 #include "math_func.hpp"
00014
00024 int LeastCommonMultiple(int a, int b)
00025 {
00026 if (a == 0 || b == 0) return 0;
00027 if (a == 1 || a == b) return b;
00028 if (b == 1) return a;
00029
00030 return a * b / GreatestCommonDivisor(a, b);
00031 }
00032
00039 int GreatestCommonDivisor(int a, int b)
00040 {
00041 while (b != 0) {
00042 int t = b;
00043 b = a % b;
00044 a = t;
00045 }
00046 return a;
00047
00048 }
00049
00056 uint32 IntSqrt(uint32 num)
00057 {
00058 uint32 res = 0;
00059 uint32 bit = 1UL << 30;
00060
00061
00062 while (bit > num) bit >>= 2;
00063
00064 while (bit != 0) {
00065 if (num >= res + bit) {
00066 num -= res + bit;
00067 res = (res >> 1) + bit;
00068 } else {
00069 res >>= 1;
00070 }
00071 bit >>= 2;
00072 }
00073
00074
00075 if (num > res) res++;
00076
00077 return res;
00078 }