Changeset c879ee in git for factory/imm.h
- Timestamp:
- Oct 19, 2012, 6:38:54 PM (11 years ago)
- Branches:
- (u'spielwiese', '5b153614cbc72bfa198d75b1e9e33dab2645d9fe')
- Children:
- 05fd55e34baa83465ce4306966c9011d1a156232
- Parents:
- 1bc7201c1a771fb5cc842ca4f475ba3ea91e697963e72b40a6237e50811b0e8745201177d25cb979
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/imm.h
r1bc7201 rc879ee 26 26 #include "int_cf.h" 27 27 28 const intINTMARK = 1;29 const intFFMARK = 2;30 const intGFMARK = 3;28 const long INTMARK = 1; 29 const long FFMARK = 2; 30 const long GFMARK = 3; 31 31 32 32 /* define type of your compilers 64 bit integer type */ … … 35 35 #endif 36 36 37 const int MINIMMEDIATE = -268435454; // -2^28-2 38 const int MAXIMMEDIATE = 268435454; // 2^28-2 37 #if SIZEOF_LONG == 4 38 const long MINIMMEDIATE = -268435454; // -2^28-2 39 const long MAXIMMEDIATE = 268435454; // 2^28-2 40 #else 41 const long MINIMMEDIATE = -(1L<<60)+2L; // -2^60-2 42 const long MAXIMMEDIATE = (1L<<60)-2L; // 2^60-2 43 #endif 44 39 45 #if defined(WINNT) && ! defined(__GNUC__) 40 46 const INT64 MINIMMEDIATELL = -268435454i64; … … 49 55 #if 1 50 56 51 inline intimm2int ( const InternalCF * const imm )52 { 53 return (( int)((long)imm)) >> 2;54 } 55 56 inline InternalCF * int2imm ( inti )57 inline long imm2int ( const InternalCF * const imm ) 58 { 59 return ((long)imm) >> 2; 60 } 61 62 inline InternalCF * int2imm ( long i ) 57 63 { 58 64 return (InternalCF*)(long)((i << 2) | INTMARK ); … … 70 76 } 71 77 72 inline InternalCF * int2imm ( inti )78 inline InternalCF * int2imm ( long i ) 73 79 { 74 80 if ( i < 0 ) … … 80 86 #endif 81 87 82 inline InternalCF * int2imm_p ( inti )88 inline InternalCF * int2imm_p ( long i ) 83 89 { 84 90 return (InternalCF*)(long)((i << 2) | FFMARK ); 85 91 } 86 92 87 inline InternalCF * int2imm_gf ( inti )93 inline InternalCF * int2imm_gf ( long i ) 88 94 { 89 95 return (InternalCF*)(long)((i << 2) | GFMARK ); … … 143 149 144 150 //{{{ conversion functions 145 inline intimm_intval ( const InternalCF* const op )151 inline long imm_intval ( const InternalCF* const op ) 146 152 { 147 153 if ( is_imm( op ) == FFMARK ) … … 253 259 inline InternalCF * imm_add ( const InternalCF * const lhs, const InternalCF * const rhs ) 254 260 { 255 intresult = imm2int( lhs ) + imm2int( rhs );261 long result = imm2int( lhs ) + imm2int( rhs ); 256 262 if ( ( result > MAXIMMEDIATE ) || ( result < MINIMMEDIATE ) ) 257 263 return CFFactory::basic( result ); … … 272 278 inline InternalCF * imm_sub ( const InternalCF * const lhs, const InternalCF * const rhs ) 273 279 { 274 intresult = imm2int( lhs ) - imm2int( rhs );280 long result = imm2int( lhs ) - imm2int( rhs ); 275 281 if ( ( result > MAXIMMEDIATE ) || ( result < MINIMMEDIATE ) ) 276 282 return CFFactory::basic( result ); … … 292 298 imm_mul ( InternalCF * lhs, InternalCF * rhs ) 293 299 { 294 INT64 result = (INT64)imm2int( lhs ) * imm2int( rhs ); 295 if ( ( result > MAXIMMEDIATELL ) || ( result < MINIMMEDIATELL ) ) { 296 InternalCF * res = CFFactory::basic( IntegerDomain, imm2int( lhs ), true ); 300 long a = imm2int( lhs ); 301 long b = imm2int( rhs ); 302 INT64 result = (INT64)a * (INT64)b; 303 if ( ( a!=0L ) && ((result/a!=b) 304 ||(result>MAXIMMEDIATE)||(result<MINIMMEDIATE) ) ) 305 { 306 InternalCF * res = CFFactory::basic( IntegerDomain, a, true ); 297 307 return res->mulcoeff( rhs ); 298 308 } 299 309 else 300 return int2imm( (int)result );310 return int2imm( result ); 301 311 } 302 312 … … 313 323 inline InternalCF * imm_div ( const InternalCF * const lhs, const InternalCF * const rhs ) 314 324 { 315 inta = imm2int( lhs );316 intb = imm2int( rhs );325 long a = imm2int( lhs ); 326 long b = imm2int( rhs ); 317 327 if ( a > 0 ) 318 328 return int2imm( a / b ); … … 328 338 return CFFactory::rational( imm2int( lhs ), imm2int( rhs ) ); 329 339 else { 330 inta = imm2int( lhs );331 intb = imm2int( rhs );340 long a = imm2int( lhs ); 341 long b = imm2int( rhs ); 332 342 if ( a > 0 ) 333 343 return int2imm( a / b ); … … 354 364 return int2imm( 0 ); 355 365 else { 356 inta = imm2int( lhs );357 intb = imm2int( rhs );366 long a = imm2int( lhs ); 367 long b = imm2int( rhs ); 358 368 if ( a > 0 ) 359 369 if ( b > 0 ) … … 363 373 else 364 374 if ( b > 0 ) { 365 intr = (-a) % b;375 long r = (-a) % b; 366 376 return int2imm( (r==0) ? r : b-r ); 367 377 } 368 378 else { 369 intr = (-a) % (-b);379 long r = (-a) % (-b); 370 380 return int2imm( (r==0) ? r : -b-r ); 371 381 } … … 387 397 if ( cf_glob_switches.isOn( SW_RATIONAL ) ) { 388 398 q = imm_divrat( lhs, rhs ); 389 r = CFFactory::basic( 0 );399 r = CFFactory::basic( 0L ); 390 400 } 391 401 else {
Note: See TracChangeset
for help on using the changeset viewer.