Changeset a1edafa
- Timestamp:
- Jul 21, 2017, 5:28:45 PM (7 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:
- 6b0b624
- Parents:
- 6d54c3a
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/math
r6d54c3a ra1edafa 10 10 // Created On : Mon Apr 18 23:37:04 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 20 21:45:07201713 // Update Count : 7712 // Last Modified On : Fri Jul 21 17:03:13 2017 13 // Update Count : 101 14 14 // 15 15 … … 83 83 static inline double _Complex pow( double _Complex x, double _Complex y ) { return cpow( x, y ); } 84 84 static inline long double _Complex pow( long double _Complex x, long double _Complex y ) { return cpowl( x, y ); } 85 86 static inline float ?\?( float x, float y ) { return powf( x, y ); }87 static inline double ?\?( double x, double y ) { return pow( x, y ); }88 static inline long double ?\?( long double x, long double y ) { return powl( x, y ); }89 static inline float _Complex ?\?( float _Complex x, _Complex float y ) { return cpowf(x, y ); }90 static inline double _Complex ?\?( double _Complex x, _Complex double y ) { return cpow( x, y ); }91 static inline long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); }92 93 static inline float ?\=?( float * x, float y ) { *x = *x \ y; return *x; }94 static inline double ?\=?( double * x, double y ) { *x = *x \ y; return *x; }95 static inline long double ?\=?( long double * x, long double y ) { *x = *x \ y; return *x; }96 static inline float _Complex ?\=?( float _Complex * x, _Complex float y ) { *x = *x \ y; return *x; }97 static inline double _Complex ?\=?( double _Complex * x, _Complex double y ) { *x = *x \ y; return *x; }98 static inline long double _Complex ?\=?( long double _Complex * x, _Complex long double y ) { *x = *x \ y; return *x; }99 100 static inline long int ?\?( long int x, unsigned long y ) { // disallow negative exponent101 if ( y == 0 ) return 1;102 if ( x == 2 ) return x << (y - 1);103 long int prod = 1;104 for ( unsigned int i = 0; i < y; i += 1 ) {105 prod = prod * x;106 } // for107 return prod;108 }109 static inline double ?\?( long int x, signed long y ) { // allow negative exponent110 if ( y >= 0 ) return (double)(x \ (unsigned int)y);111 else return 1.0 / x \ (unsigned int)(-y);112 }113 static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } )114 T ?\?( T x, unsigned long y ) {115 T prod = 1;116 for ( unsigned int i = 1; i < y; i += 1 ) {117 prod = prod * x;118 } // for119 return prod;120 }121 static inline long int ?\=?( long int * x, unsigned long y ) { *x = *x \ y; return *x; }122 static inline int ?\=?( int * x, unsigned long y ) { *x = *x \ y; return *x; }123 85 124 86 //---------------------- Logarithm ---------------------- -
src/prelude/builtins.c
r6d54c3a ra1edafa 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // builtins.c -- 8 // 9 // Author : Peter A. Buhr 10 // Created On : Fri Jul 21 16:21:03 2017 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 17:01:54 2017 13 // Update Count : 11 14 // 15 16 // exception implementation 17 1 18 typedef unsigned long long __cfaabi_exception_type_t; 2 19 3 20 #include "../libcfa/exception.h" 21 22 // exponentiation operator implementation 23 24 extern "C" { 25 float powf( float x, float y ); 26 double pow( double x, double y ); 27 long double powl( long double x, long double y ); 28 float _Complex cpowf( float _Complex x, _Complex float z ); 29 double _Complex cpow( double _Complex x, _Complex double z ); 30 long double _Complex cpowl( long double _Complex x, _Complex long double z ); 31 } // extern "C" 32 33 static inline float ?\?( float x, float y ) { return powf( x, y ); } 34 static inline double ?\?( double x, double y ) { return pow( x, y ); } 35 static inline long double ?\?( long double x, long double y ) { return powl( x, y ); } 36 static inline float _Complex ?\?( float _Complex x, _Complex float y ) { return cpowf(x, y ); } 37 static inline double _Complex ?\?( double _Complex x, _Complex double y ) { return cpow( x, y ); } 38 static inline long double _Complex ?\?( long double _Complex x, _Complex long double y ) { return cpowl( x, y ); } 39 40 static inline long int ?\?( long int pe, unsigned long y ) { // disallow negative exponent 41 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 44 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; 49 } // ?\? 50 51 // FIX ME, cannot resolve the "T po = 1". 52 53 // static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); } ) 54 // T ?\?( T pe, unsigned long y ) { 55 // if ( y == 0 ) return 1; 56 // T po = 1; 57 // for ( ; y > 1; y >>= 1 ) { // squaring exponentiation, O(log2 y) 58 // if ( (y & 1) == 1 ) po = po * pe; // odd ? 59 // pe = pe * pe; 60 // } // for 61 // return pe * po; 62 // } // ?\? 63 64 // unsigned computation may be faster and larger 65 static inline unsigned long int ?\?( unsigned long int pe, unsigned long y ) { // disallow negative exponent 66 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 69 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; 74 } // ?\? 75 76 static inline double ?\?( long int x, signed long y ) { // allow negative exponent 77 if ( y >= 0 ) return (double)(x \ (unsigned long int)y); 78 else return 1.0 / x \ (unsigned int)(-y); 79 } // ?\? 80 81 static inline forall( otype T | { void ?{}( T * this, one_t ); T ?*?( T, T ); double ?/?( double, T ); } ) 82 double ?\?( T x, signed long y ) { 83 if ( y >= 0 ) return (double)(x \ (unsigned long int)y); 84 else return 1.0 / x \ (unsigned int)(-y); 85 } // ?\? 86 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; } 91 92 // Local Variables: // 93 // mode: c // 94 // tab-width: 4 // 95 // End: //
Note: See TracChangeset
for help on using the changeset viewer.