Ignore:
Timestamp:
Jul 22, 2017, 11:05:35 AM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
637ff81, 72457b6
Parents:
6b0b624
git-author:
Peter A. Buhr <pabuhr@…> (07/22/17 10:59:19)
git-committer:
Peter A. Buhr <pabuhr@…> (07/22/17 11:05:35)
Message:

updates to exponential operator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/prelude/builtins.c

    r6b0b624 rfe97a7d8  
    1010// Created On       : Fri Jul 21 16:21:03 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 17:01:54 2017
    13 // Update Count     : 11
     12// Last Modified On : Sat Jul 22 10:34:20 2017
     13// Update Count     : 13
    1414//
    1515
     
    3838static inline long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); }
    3939
    40 static inline long int ?\?( long int pe, unsigned long y ) { // disallow negative exponent
     40static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent
    4141        if ( y == 0 ) return 1;                                                         // base case
    42     if ( pe == 2 ) return pe << (y - 1);                                // special case, positive shifting only
    43     typeof( pe ) po = 1;                                                                // accumulate odd product
     42    if ( ep == 2 ) return ep << (y - 1);                                // special case, positive shifting only
     43    typeof( ep ) op = 1;                                                                // accumulate odd product
    4444    for ( ; y > 1; y >>= 1 ) {                                                  // squaring exponentiation, O(log2 y)
    45                 if ( (y & 1) == 1 ) po *= pe;                                   // odd ?
    46                 pe *= pe;
    47         } // while
    48     return pe * po;
     45                if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
     46                ep *= ep;
     47        } // for
     48    return ep * op;
    4949} // ?\?
    5050
    51 // FIX ME, cannot resolve the "T po = 1".
     51// FIX ME, cannot resolve the "T op = 1".
    5252
    5353// static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } )
    54 // T ?\?( T pe, unsigned long y ) {
     54// T ?\?( T ep, unsigned long int y ) {
    5555//     if ( y == 0 ) return 1;
    56 //     T po = 1;
     56//     T op = 1;
    5757//     for ( ; y > 1; y >>= 1 ) {                                                       // squaring exponentiation, O(log2 y)
    58 //              if ( (y & 1) == 1 ) po = po * pe;                               // odd ?
    59 //              pe = pe * pe;
     58//              if ( (y & 1) == 1 ) op = op * ep;                               // odd ?
     59//              ep = ep * ep;
    6060//     } // for
    61 //     return pe * po;
     61//     return ep * op;
    6262// } // ?\?
    6363
    6464// unsigned computation may be faster and larger
    65 static inline unsigned long int ?\?( unsigned long int pe, unsigned long y ) { // disallow negative exponent
     65static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent
    6666        if ( y == 0 ) return 1;                                                         // base case
    67     if ( pe == 2 ) return pe << (y - 1);                                // special case, positive shifting only
    68     typeof( pe ) po = 1;                                                                // accumulate odd product
     67    if ( ep == 2 ) return ep << (y - 1);                                // special case, positive shifting only
     68    typeof( ep ) op = 1;                                                                // accumulate odd product
    6969    for ( ; y > 1; y >>= 1 ) {                                                  // squaring exponentiation, O(log2 y)
    70                 if ( (y & 1) == 1 ) po *= pe;                                   // odd ?
    71                 pe *= pe;
    72         } // while
    73     return pe * po;
     70                if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
     71                ep *= ep;
     72        } // for
     73    return ep * op;
    7474} // ?\?
    7575
    76 static inline double ?\?( long int x, signed long y ) { // allow negative exponent
     76static inline double ?\?( long int x, signed long int y ) {     // allow negative exponent
    7777    if ( y >=  0 ) return (double)(x \ (unsigned long int)y);
    7878    else return 1.0 / x \ (unsigned int)(-y);
     
    8080
    8181static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); double ?/?( double, T ); } )
    82 double ?\?( T x, signed long y ) {
     82double ?\?( T x, signed long int y ) {
    8383    if ( y >=  0 ) return (double)(x \ (unsigned long int)y);
    84     else return 1.0 / x \ (unsigned int)(-y);
     84    else return 1.0 / x \ (unsigned long int)(-y);
    8585} // ?\?
    8686
    87 static inline long int ?\=?( long int * x, unsigned long y ) { *x = *x \ y; return *x; }
    88 static inline long int ?\=?( unsigned long int * x, unsigned long y ) { *x = *x \ y; return *x; }
    89 static inline int ?\=?( int * x, unsigned long y ) { *x = *x \ y; return *x; }
    90 static inline int ?\=?( unsigned int * x, unsigned long y ) { *x = *x \ y; return *x; }
     87static inline long int ?\=?( long int * x, unsigned long int y ) { *x = *x \ y; return *x; }
     88static inline unsigned long int ?\=?( unsigned long int * x, unsigned long int y ) { *x = *x \ y; return *x; }
     89static inline int ?\=?( int * x, unsigned long int y ) { *x = *x \ y; return *x; }
     90static inline unsigned int ?\=?( unsigned int * x, unsigned long int y ) { *x = *x \ y; return *x; }
    9191
    9292// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.