Ignore:
Timestamp:
Feb 26, 2018, 10:44:53 AM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
17fc7a5
Parents:
5a806be4
Message:

Allow builtin objects to be constructed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/prelude/builtins.c

    r5a806be4 rdf7a162  
    4444static inline long int ?\?( long int ep, unsigned long int y ) { // disallow negative exponent
    4545        if ( y == 0 ) return 1;                                                         // base case
    46     if ( ep == 2 ) return ep << (y - 1);                                // special case, positive shifting only
    47     typeof( ep ) op = 1;                                                                // accumulate odd product
    48     for ( ; y > 1; y >>= 1 ) {                                                  // squaring exponentiation, O(log2 y)
     46        if ( ep == 2 ) return ep << (y - 1);                            // special case, positive shifting only
     47        typeof( ep ) op = 1;                                                            // accumulate odd product
     48        for ( ; y > 1; y >>= 1 ) {                                                      // squaring exponentiation, O(log2 y)
    4949                if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
    5050                ep *= ep;
    5151        } // for
    52     return ep * op;
     52        return ep * op;
    5353} // ?\?
    5454
    55 // FIX ME, cannot resolve the "T op = 1".
    56 
    57 // static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } )
    58 // T ?\?( T ep, unsigned long int y ) {
    59 //     if ( y == 0 ) return 1;
    60 //     T op = 1;
    61 //     for ( ; y > 1; y >>= 1 ) {                                                       // squaring exponentiation, O(log2 y)
    62 //              if ( (y & 1) == 1 ) op = op * ep;                               // odd ?
    63 //              ep = ep * ep;
    64 //     } // for
    65 //     return ep * op;
    66 // } // ?\?
     55static inline forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
     56T ?\?( T ep, unsigned long int y ) {
     57        if ( y == 0 ) return 1;
     58        T op = 1;
     59        for ( ; y > 1; y >>= 1 ) {                                                      // squaring exponentiation, O(log2 y)
     60                if ( (y & 1) == 1 ) op = op * ep;                               // odd ?
     61                ep = ep * ep;
     62        } // for
     63        return ep * op;
     64} // ?\?
    6765
    6866// unsigned computation may be faster and larger
    6967static inline unsigned long int ?\?( unsigned long int ep, unsigned long int y ) { // disallow negative exponent
    7068        if ( y == 0 ) return 1;                                                         // base case
    71     if ( ep == 2 ) return ep << (y - 1);                                // special case, positive shifting only
    72     typeof( ep ) op = 1;                                                                // accumulate odd product
    73     for ( ; y > 1; y >>= 1 ) {                                                  // squaring exponentiation, O(log2 y)
     69        if ( ep == 2 ) return ep << (y - 1);                            // special case, positive shifting only
     70        typeof( ep ) op = 1;                                                            // accumulate odd product
     71        for ( ; y > 1; y >>= 1 ) {                                                      // squaring exponentiation, O(log2 y)
    7472                if ( (y & 1) == 1 ) op *= ep;                                   // odd ?
    7573                ep *= ep;
    7674        } // for
    77     return ep * op;
     75        return ep * op;
    7876} // ?\?
    7977
    8078static inline double ?\?( long int x, signed long int y ) {     // allow negative exponent
    81     if ( y >=  0 ) return (double)(x \ (unsigned long int)y);
    82     else return 1.0 / x \ (unsigned int)(-y);
     79        if ( y >=  0 ) return (double)(x \ (unsigned long int)y);
     80        else return 1.0 / x \ (unsigned int)(-y);
    8381} // ?\?
    8482
Note: See TracChangeset for help on using the changeset viewer.