Changeset dcbb03b for src/prelude


Ignore:
Timestamp:
Mar 1, 2018, 9:29:03 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/prelude/builtins.c

    rb002261 rdcbb03b  
    5858static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent
    5959        if ( y == 0 ) return 1;                                                         // base case
    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)
     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)
    6363                if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
    6464                ep *= ep;
    6565        } // for
    66     return ep * op;
     66        return ep * op;
    6767} // ?\?
    6868
    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 // } // ?\?
     69static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
     70T ?\?( 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} // ?\?
    8179
    8280// unsigned computation may be faster and larger
    8381static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent
    8482        if ( y == 0 ) return 1;                                                         // base case
    85     if ( ep == 2 ) return ep << (y - 1);                                // special case, positive shifting only
    86     typeof( ep ) op = 1;                                                                // accumulate odd product
    87     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)
    8886                if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
    8987                ep *= ep;
    9088        } // for
    91     return ep * op;
     89        return ep * op;
    9290} // ?\?
    9391
    9492static 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);
    9795} // ?\?
    9896
Note: See TracChangeset for help on using the changeset viewer.