Changeset d34f24 in git for factory/canonicalform.cc
- Timestamp:
- Jul 31, 1997, 3:10:10 PM (27 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 19f74feb1a8fde7c5b3782b0cea34f4990189986
- Parents:
- ae5205abe0fd692a06f68fb3c35cad2f62c5ce46
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/canonicalform.cc
rae5205 rd34f24 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: canonicalform.cc,v 1.1 2 1997-07-30 15:06:33schmidt Exp $ */2 /* $Id: canonicalform.cc,v 1.13 1997-07-31 13:10:10 schmidt Exp $ */ 3 3 4 4 #include <config.h> … … 1244 1244 } 1245 1245 1246 CanonicalForm 1247 CanonicalForm::sqrt ( ) const 1246 //{{{ CanonicalForm CanonicalForm::sqrt() const 1247 //{{{ docu 1248 // 1249 // sqrt() - calculate integer square root. 1250 // 1251 // CO has to be an integer greater or equal zero. Returns the 1252 // largest integer less or equal sqrt(CO). 1253 // 1254 // In the immediate case, we use the newton method to find the 1255 // root. The algorithm is from H. Cohen - A Course in 1256 // Computational Algebraic Number Theory, ch. 1.7.1. 1257 // 1258 //}}} 1259 CanonicalForm 1260 CanonicalForm::sqrt() const 1248 1261 { 1249 1262 if ( is_imm( value ) ) { 1250 ASSERT( is_imm( value ) == INTMARK, "not implemented" ); 1251 int a = imm2int( value ); 1252 ASSERT( a >= 0, "arg to sqrt less than zero" ); 1253 if ( a == 0 || a == 1 ) 1254 return CanonicalForm( CFFactory::basic( a ) ); 1255 else { 1256 int x0, x1 = a; 1257 long long int h; 1263 ASSERT( is_imm( value ) == INTMARK, "sqrt() not implemented" ); 1264 int n = imm2int( value ); 1265 ASSERT( n >= 0, "arg to sqrt() less than zero" ); 1266 if ( n == 0 || n == 1 ) 1267 return CanonicalForm( CFFactory::basic( n ) ); 1268 else { 1269 int x, y = n; 1258 1270 do { 1259 x0 = x1; 1260 h = (long long int)x0 * x0 + a - 1; 1261 if ( h % (2 * x0) == 0 ) 1262 x1 = h / (2 * x0); 1263 else 1264 x1 = (h - 1) / (2 * x0); 1265 } while ( x1 < x0 ); 1266 return CanonicalForm( CFFactory::basic( x1 ) ); 1271 x = y; 1272 // the intermediate result may not fit into an 1273 // integer, but the result does 1274 y = (unsigned int)(x + n/x)/2; 1275 } while ( y < x ); 1276 return CanonicalForm( CFFactory::basic( x ) ); 1267 1277 } 1268 1278 } … … 1270 1280 return CanonicalForm( value->sqrt() ); 1271 1281 } 1272 1273 //{{{ int CanonicalForm::ilog2( ) const 1282 //}}} 1283 1284 //{{{ int CanonicalForm::ilog2 () const 1274 1285 //{{{ docu 1275 1286 // 1276 1287 // ilog2() - integer logarithm to base 2. 1277 1288 // 1278 // Returns the largest integer smaller thanlogarithm of CO to1279 // base 2. CO should be a ninteger.1289 // Returns the largest integer less or equal logarithm of CO to 1290 // base 2. CO should be a positive integer. 1280 1291 // 1281 1292 //}}} 1282 1293 int 1283 CanonicalForm::ilog2 () const1294 CanonicalForm::ilog2 () const 1284 1295 { 1285 1296 if ( is_imm( value ) ) { 1286 ASSERT( is_imm( value ) == INTMARK, " not implemented" );1297 ASSERT( is_imm( value ) == INTMARK, "ilog2() not implemented" ); 1287 1298 int a = imm2int( value ); 1288 ASSERT( a > 0, " log arg <= 0" );1299 ASSERT( a > 0, "arg to ilog2() less or equal zero" ); 1289 1300 int n = -1; 1290 1301 while ( a != 0 ) {
Note: See TracChangeset
for help on using the changeset viewer.