// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // math.cpp -- // // Author : Andrew Beach // Created On : Mon Nov 25 16:20:00 2024 // Last Modified By : Andrew Beach // Created On : Mon Nov 27 15:11:00 2024 // Update Count : 0 // #include "math.hfa" #include #pragma GCC visibility push(default) // Implementation of power functions (from the prelude): #define __CFA_EXP__() \ if ( y == 0 ) return 1; /* convention */ \ __CFA_EXP_INT__( /* special cases for integral types */ \ if ( x == 1 ) return 1; /* base case */ \ if ( x == 2 ) return x << (y - 1); /* positive shifting */ \ if ( y >= sizeof(y) * CHAR_BIT ) return 0; /* immediate overflow, negative exponent > 2^size-1 */ \ ) \ typeof(x) op = 1; /* accumulate odd product */ \ typeof(x) w = x; /* FIX-ME: possible bug in the box pass changing value argument through parameter */ \ for ( ; y > 1; y >>= 1 ) { /* squaring exponentiation, O(log2 y) */ \ if ( (y & 1) == 1 ) op = op * w; /* odd ? */ \ w = w * w; \ } \ return w * op #define __CFA_EXP_INT__(...) __VA_ARGS__ int ?\?( int x, unsigned int y ) { __CFA_EXP__(); } long int ?\?( long int x, unsigned long int y ) { __CFA_EXP__(); } long long int ?\?( long long int x, unsigned long long int y ) { __CFA_EXP__(); } unsigned int ?\?( unsigned int x, unsigned int y ) { __CFA_EXP__(); } unsigned long int ?\?( unsigned long int x, unsigned long int y ) { __CFA_EXP__(); } unsigned long long int ?\?( unsigned long long int x, unsigned long long int y ) { __CFA_EXP__(); } #undef __CFA_EXP_INT__ #define __CFA_EXP_INT__(...) forall( OT | { void ?{}( OT & this, one_t ); OT ?*?( OT, OT ); } ) { OT ?\?( OT x, unsigned int y ) { __CFA_EXP__(); } OT ?\?( OT x, unsigned long int y ) { __CFA_EXP__(); } OT ?\?( OT x, unsigned long long int y ) { __CFA_EXP__(); } } // distribution #undef __CFA_EXP_INT__ #undef __CFA_EXP__