Changeset 72b4d96 in tol
- Timestamp:
- Feb 8, 2012, 6:04:13 PM (15 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- b83b8ed3
- Parents:
- 2c0158d
- Location:
- tol
- Files:
-
- 3 edited
-
bmath/barith/arith.cpp (modified) (2 diffs)
-
bmath/barith/tol_barith.h (modified) (1 diff)
-
btol/real_type/datgra.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/bmath/barith/arith.cpp
r2c0158d r72b4d96 27 27 #include <tol/tol_bout.h> 28 28 #include <tol/tol_barith.h> 29 #include <boost/math/common_factor_rt.hpp> 29 30 30 31 BTraceInit("arith.cpp"); … … 265 266 while(N<n); 266 267 } 268 269 270 //-------------------------------------------------------------------- 271 int GreatestCommonDivisor(int a, int b) 272 273 /*! Return the Greatest Common Divisor of two integers 274 */ 275 //-------------------------------------------------------------------- 276 { 277 return(boost::math::gcd(a,b)); 278 } 279 280 //-------------------------------------------------------------------- 281 int LeastCommonMultiple(int a, int b) 282 283 /*! Return the Least Common Multiple of two integers 284 */ 285 //-------------------------------------------------------------------- 286 { 287 return(boost::math::lcm(a,b)); 288 } 289 290 //-------------------------------------------------------------------- 291 int GreatestCommonDivisor(const BArray<int>& a) 292 293 /*! Return the Greatest Common Divisor of an array of integers 294 */ 295 //-------------------------------------------------------------------- 296 { 297 int s = a.Size(); 298 if(!s) { return(0); } 299 int i; 300 int gcd = a[0]; 301 for(i=1; i<s; i++) 302 { 303 gcd = boost::math::gcd(gcd,a[i]); 304 } 305 return(gcd); 306 } 307 308 //-------------------------------------------------------------------- 309 int LeastCommonMultiple(const BArray<int>& a) 310 311 /*! Return the Least Common Multiple of an array of integers 312 */ 313 //-------------------------------------------------------------------- 314 { 315 int s = a.Size(); 316 if(!s) { return(0); } 317 int i; 318 int lcm = a[0]; 319 for(i=1; i<s; i++) 320 { 321 lcm = boost::math::lcm(lcm,a[i]); 322 } 323 return(lcm); 324 } 325 326 -
tol/bmath/barith/tol_barith.h
r2c0158d r72b4d96 50 50 TOL_API void FirstPrimes(BInt n, BArray<BInt>& p); 51 51 52 TOL_API int GreatestCommonDivisor(int a, int b); 53 TOL_API int LeastCommonMultiple(int a, int b); 54 TOL_API int GreatestCommonDivisor(const BArray<int>& a); 55 TOL_API int LeastCommonMultiple(const BArray<int>& a); 56 52 57 inline ldouble Abs (BInt a) { return(fabsl(a)); } 53 58 inline ldouble Sqrt (BInt a) { return(sqrtl(a)); } -
tol/btol/real_type/datgra.cpp
r2c0158d r72b4d96 39 39 #include <tol/tol_bmatfun.h> 40 40 #include <tol/tol_bvmat.h> 41 #include <tol/tol_barith.h> 41 42 #include <float.h> 42 43 … … 1076 1077 1077 1078 1079 //-------------------------------------------------------------------- 1080 DeclareContensClass(BDat, BDatTemporary, BDatGreatestCommonDivisor); 1081 DefIntOpr(1, BDatGreatestCommonDivisor, "GreatestCommonDivisor", 1, 0, 1082 "(Real x1, [ Real x2 , ...])", 1083 I2("Returns the Greatest Common Divisor of a list of positive " 1084 "integer numbers. If any given number is unklnown or is not " 1085 "integer and positive the unknown value will be returned.", 1086 "Devuelve el Máximo Común Divisor de una lista de números " 1087 "enteros positivos. Si algún número es desconocido o no es entero " 1088 "y positivo se devolverá el valor desconocido."), 1089 BOperClassify::RealArythmetic_); 1090 void BDatGreatestCommonDivisor::CalcContens() 1091 //-------------------------------------------------------------------- 1092 { 1093 int gcd = -1; 1094 int n; 1095 for(n=1; n<=NumArgs(); n++) 1096 { 1097 BDat& x = Dat(Arg(n)); 1098 if(x.IsUnknown() || (x<=0) || !x.IsInteger()) { return; } 1099 if(gcd == -1) { gcd = (int)x.Value(); } 1100 else { gcd = GreatestCommonDivisor(gcd, (int)x.Value()); } 1101 } 1102 contens_ = gcd; 1103 } 1104 1105 //-------------------------------------------------------------------- 1106 DeclareContensClass(BDat, BDatTemporary, BDatLeastCommonMultiple); 1107 DefIntOpr(1, BDatLeastCommonMultiple, "LeastCommonMultiple", 1, 0, 1108 "(Real x1, [ Real x2 , ...])", 1109 I2("Returns the Greatest Common Divisor of a list of positive " 1110 "integer numbers. If any given number is unklnown or is not " 1111 "integer and positive the unknown value will be returned.", 1112 "Devuelve el Máximo Común Divisor de una lista de números " 1113 "enteros positivos. Si algún número es desconocido o no es entero " 1114 "y positivo se devolverá el valor desconocido."), 1115 BOperClassify::RealArythmetic_); 1116 void BDatLeastCommonMultiple::CalcContens() 1117 //-------------------------------------------------------------------- 1118 { 1119 int lcm = -1; 1120 int n; 1121 for(n=1; n<=NumArgs(); n++) 1122 { 1123 BDat& x = Dat(Arg(n)); 1124 if(x.IsUnknown() || (x<=0) || !x.IsInteger()) { return; } 1125 if(lcm == -1) { lcm = (int)x.Value(); } 1126 else { lcm = LeastCommonMultiple(lcm, (int)x.Value()); } 1127 } 1128 contens_ = lcm; 1129 } 1130
Note: See TracChangeset
for help on using the changeset viewer.
