Changeset dcbb03b for src/prelude
- Timestamp:
- Mar 1, 2018, 9:29:03 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1f37ed02
- Parents:
- b002261 (diff), 446ffa3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
src/prelude/builtins.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/prelude/builtins.c
rb002261 rdcbb03b 58 58 static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent 59 59 if ( y == 0 ) return 1; // base case 60 if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only61 typeof( ep ) op = 1; // accumulate odd product62 for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)60 if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only 61 typeof( ep ) op = 1; // accumulate odd product 62 for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) 63 63 if ( (y & 1) == 1 ) op *= ep; // odd ? 64 64 ep *= ep; 65 65 } // for 66 return ep * op;66 return ep * op; 67 67 } // ?\? 68 68 69 // FIX ME, cannot resolve the "T op = 1". 70 71 // static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } ) 72 // T ?\?( T ep, unsigned long int y ) { 73 // if ( y == 0 ) return 1; 74 // T op = 1; 75 // for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) 76 // if ( (y & 1) == 1 ) op = op * ep; // odd ? 77 // ep = ep * ep; 78 // } // for 79 // return ep * op; 80 // } // ?\? 69 static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } ) 70 T ?\?( T ep, unsigned long int y ) { 71 if ( y == 0 ) return 1; 72 T op = 1; 73 for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) 74 if ( (y & 1) == 1 ) op = op * ep; // odd ? 75 ep = ep * ep; 76 } // for 77 return ep * op; 78 } // ?\? 81 79 82 80 // unsigned computation may be faster and larger 83 81 static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent 84 82 if ( y == 0 ) return 1; // base case 85 if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only86 typeof( ep ) op = 1; // accumulate odd product87 for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y)83 if ( ep == 2 ) return ep << (y - 1); // special case, positive shifting only 84 typeof( ep ) op = 1; // accumulate odd product 85 for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) 88 86 if ( (y & 1) == 1 ) op *= ep; // odd ? 89 87 ep *= ep; 90 88 } // for 91 return ep * op;89 return ep * op; 92 90 } // ?\? 93 91 94 92 static inline double ?\?( long int x, signed long int y ) { // allow negative exponent 95 if ( y >= 0 ) return (double)(x \ (unsigned long int)y);96 else return 1.0 / x \ (unsigned int)(-y);93 if ( y >= 0 ) return (double)(x \ (unsigned long int)y); 94 else return 1.0 / x \ (unsigned int)(-y); 97 95 } // ?\? 98 96
Note:
See TracChangeset
for help on using the changeset viewer.