char* PasswordGenerator (NPKIBruteForce *bforce) { uint32_t i = 0; for (i = 0; i < bforce->pw_now_len; i++) // bforce->password[i] = bforce->pw_charset[bforce->pw_cursor / ipow(charset_len, i) % charset_len]; bforce->password[i] = bforce->pw_charset[(bforce->pw_cursor % ipow(charset_len, i+1)) / ipow(charset_len, i)]; bforce->password[i] = '\0'; return bforce->password; }
void ppGPowRq (void* y, PrimeExponent pe, hDim_t lts, hDim_t rts, hInt_t q) { hDim_t p = pe.prime; hShort_t e = pe.exponent; if (p != 2) { gPowRq ((hInt_t*)y, lts*ipow(p,e-1), rts, p, q); } }
U solve(U a, U b){ U min_k, max_k, sum, i, k, low, high; U counts[64]; memset(counts, 0, sizeof (counts)); sum = 0; min_k = 1; max_k = 64 - __builtin_clzll(b); for (k = max_k;k >= min_k; --k){ if (k > 1){ low = floor(kth_root2(a, k)); high = ceil(kth_root2(b, k)); } else { low = a; high = b; } while (ipow(low, k) < a){ ++low; double x = pow(low, k); if (x > MAX) goto next;; } if (ipow(low, k) > b) continue; while (pow(high, k) > MAX) --high; while (ipow(high, k) > b) --high; if (ipow(high, k) < a) continue; counts[k] = high - low + 1; for (i = k + k;i <= max_k; i += k){ counts[k] -= counts[i]; } sum += counts[k] * k; next:; } return sum; }
void ppGCRTC (void* y, hDim_t lts, hDim_t rts, PrimeExponent pe, void* gcoeffs, hInt_t q) { hDim_t p = pe.prime; hShort_t e = pe.exponent; #ifdef DEBUG_MODE printf("gcoeffs for p=%" PRId32 ", e=%" PRId16 "\t[", pe.prime, pe.exponent); int i; for(i = 0; i < ((p-1)*ipow(p,e-1)); i++) { printf("(%f,%f),", ((complex_t*)gcoeffs)[i].real, ((complex_t*)gcoeffs)[i].imag); } printf("]\n"); #endif if (p != 2) { gCRTC ((complex_t*)y, lts*ipow(p,e-1), rts, p, (complex_t*)gcoeffs); } }
static QByteArray randomByteArray(int size) { QByteArray out; int bpc=(ipow(2,sizeof(char)*8)); for(int i=0; i<size; ++i) { const char ch=(qrand() % bpc); out.append(ch); } return out; }
double freesteam_region3_cp_rhoT(double rho, double T){ DEFINE_DELTAU(rho,T); return R * ( -SQ(tau) * phitautau(del,tau) + ( ipow (del * phidel(del,tau) - del * tau * phideltau(del,tau), 2) / (2 * del * phidel(del,tau) + SQ(del) * phideldel(del,tau)) ) ); }
float frrand(float low, float hi) { float r = hi + low; int p = 5; // arbitrary precision int n = ipow(10,p); float v = (float)(rand()%n)/(n-1); float x = (v * r) + low; //printf("frand [%lf, %lf] n=%d, v=%lf, x=%lf\n", low, hi, n, v,x); return x; }
double freesteam_region3_w_rhoT(double rho, double T){ DEFINE_DELTAU(rho,T); return sqrt(R * T * ( 2 * del * phidel(del,tau) + SQ(del) * phideldel(del,tau) - ( ipow (del * phidel(del,tau) - del * tau * phideltau(del,tau), 2) / (SQ(tau) * phitautau(del,tau)) ) )); }
/* coefficients for spline of order >3 */ static void splinen(float* c, float t, float* a, int n) { for (int i = 0; i < n+1; i++) c[i] = 0; for(int k=0; k <= n+1; k++) { float xn = ipow(t+k, n); for(int i=k; i <= n; i++) c[i] += a[i-k]*xn; } }
/* For each bit sequence from 0 to the max number, find the sum along that path. */ void getBestPath(int numBits, int size, int triangle[][size]) { int bitArray[numBits]; //Store each binary count in an array int bestPath[numBits]; int bestSum = 0; int currentSum = 0; int maxNum = ipow(2, numBits); int i; int j; for (i = 0; i < maxNum; i++) { for (j = numBits; j > 0; j--) { // Get bit sequence and store it in a bit array. int currentBit = (i/ipow(2, j - 1)) % 2; bitArray[j - 1] = currentBit; } currentSum = sumOfPath(size, triangle, bitArray, numBits); if (currentSum > bestSum) { bestSum = currentSum; int k; for (k = 0; k < numBits; k++) { bestPath[k] = bitArray[k]; } } } //Print Best Sum and the Path printf("Best Sum: %d\n", bestSum); printf("Path from apex: "); int l; for (l = 0; l < numBits; l++) { if (bestPath[l] == 0) { printf("Left "); } else { printf("Right "); } //printf("%d ", bestPath[l]); } }
inline T iroot(T x) { T r = (T) std::pow((double) x, 1.0 / N); while (ipow(r, N) > x) r--; while (ipow_less_equal(r + 1, N, x)) r++; return r; }
void number_to_str(float number, char *str, int afterdecimal){ int integerPart = (int)number; float floatPart = number - (float)integerPart; int integerToString = intToStr(integerPart, str, 0); if (afterdecimal != 0) { str[integerToString] = '.'; floatPart = floatPart * ipow(10, afterdecimal); intToStr(abs((int)floatPart), str + integerToString + 1, afterdecimal); } }
/* * Calculate Index of State, the index is stored in p variable. * The State Vector is translated to an index, no index colision is accepted */ void inline getIndexOfState(long *p, long C, long G, long B, long *state) { long i; long n = C-1; *p = 0; B = B+1; for (i = 0; i < C; i++) { *p = *p + state[i]*ipow(B,n); n = n-1; } *p = *p*(G+1) + state[C]; }
/* rundet eine Fließkommazahl auf eine bestimme Stelle hinter dem Komma */ gdouble round_digits(gdouble x, guint digits) { gint n; n = ipow(10, digits); x *= n; x = (gdouble) ROUND(x, glong); x /= n; return x; }
uint64_t SetCursorFromInitialPW (NPKIBruteForce *bforce) { bforce->pw_now_len = strlen(bforce->pw_init); bforce->pw_cursor = 0; for (uint32_t i = 0; i < bforce->pw_now_len; i++) bforce->pw_cursor += (GetSerialFromCharset(bforce, bforce->pw_init[i]) * ipow(charset_len, i)); strncpy(bforce->password, bforce->pw_init, MAX_PASSWORD); bforce->password[MAX_PASSWORD-1] = '\0'; return bforce->pw_cursor; }
void makeTree(int depth, int nary, edgefn ef) { unsigned int i, j; unsigned int n = (ipow(nary,depth)-1)/(nary-1); /* no. of non-leaf nodes */ unsigned int idx = 2; for (i = 1; i <= n; i++) { for (j = 0; j < nary; j++) { ef (i, idx++); } } }
/** * @brief Initialize an area of memory for heap use. * @param heap_base A pointer to the base physical address of the heap memory area. * @param mpu_region_size The MPU region size (MPU_REGION_SIZE_xxxx). * @return A pointer to the heap state record. * @note heap_base should be aligned on the size of the region * For instance MPU_REGION_SIZE_64KB boundary would start at 0x00010000, 0x00020000, etc... * @note Each MPU protected heap will consume 2 x MPU regions. The first allows access, the second denies. */ heap_state_t* bitmap_heap_mpu_init(void* heap_base, uint8_t mpu_region_size) { int lvl = caribou_lib_lock(); uint32_t region_size_bytes = (uint32_t)ipow(2,mpu_region_size+1); heap_state_t* rc=NULL; uint32_t heap_end = (heap_base + region_size_bytes)-1; bitmap_heap_init(heap_base,heap_end); rc = HEAP_STATE(heap_num); rc->heap_flags |= CARIBOU_BITMAP_HEAP_MPU; /* This is an MPU heap */ rc->heap_subregion_size = region_size_bytes/8; /* Calculate the subregion size */ /** The first MPU region contains the User Read Only attribute */ /* Take next available H/W region */ HEAP_STATE(heap_num)->heap_flags |= heap_mpu_num; MPU->RBAR = ((uint32_t)heap_base | (1<<4) | heap_mpu_num++); /* Set the region base address for region heap_mpu_num */ MPU->RASR = ( ((mpu_region_size << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | /* Set the Region Size */ ((MPU_REGION_FULL_ACCESS << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | /* Make User Full Access */ //((MPU_ACCESS_SHAREABLE << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | /* Sharable (DMA?) */ //((MPU_ACCESS_CACHEABLE << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | /* Cacheable? */ ((MPU_ACCESS_BUFFERABLE << MPU_RASR_B_Pos) & MPU_RASR_B_Msk) | /* Bufferable? */ ((MPU_INSTRUCTION_ACCESS_ENABLE << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | /* Instructions Access? */ (MPU_REGION_ENABLE << MPU_RASR_ENABLE_Pos) /* Enable the region */ ); /** The second MPU region contains the User Read Only attribute (higher numbered region takes priority) */ /* Take next available H/W region */ MPU->RBAR = ((uint32_t)heap_base | (1<<4) | heap_mpu_num++); /* Set the region base address for region heap_mpu_num*/ MPU->RASR = ( ((mpu_region_size << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | /* Set the Region Size */ ((MPU_REGION_PRIV_RW_URO << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | /* Make User Read Only */ //((MPU_ACCESS_SHAREABLE << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | /* Sharable (DMA?) */ //((MPU_ACCESS_CACHEABLE << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | /* Cacheable? */ ((MPU_ACCESS_BUFFERABLE << MPU_RASR_B_Pos) & MPU_RASR_B_Msk) | /* Bufferable? */ ((MPU_INSTRUCTION_ACCESS_ENABLE << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | /* Instructions Access? */ (MPU_REGION_ENABLE << MPU_RASR_ENABLE_Pos) /* Enable the region */ ); //MPU->CTRL |= (MPU_REGION_ENABLE | (1<<MPU_CTRL_PRIVDEFENA_Pos)); /* Begin MPU protection */ MPU->RASR |= (0x01<<MPU_RASR_SRD_Pos); /* disable protection to subregion #0 (bitmap) */ /* Data Barrier */ __DSB(); /* Instruction Barrier */ __ISB(); caribou_lib_lock_restore(lvl); return rc; }
int main(int argc, char *argv[]) { const cl_uint numBodies = 10; float *m = cl_malloc_array(float, numBodies); float *t = cl_malloc_array(float, numBodies); cl_float4 *a = cl_malloc_array(cl_float4, numBodies); cl_float4 *v = cl_malloc_array(cl_float4, numBodies); cl_float4 *p = cl_malloc_array(cl_float4, numBodies); #ifdef CL_BUILD_RUNTIME cl_uint type = clGetTypeFromString(CL_USER_DEVICE_TYPE); cl_uint count = CL_USER_DEVICE_COUNT; cl_environment_t *pEnv = clCreateEnvironment(KDIR"kernel_nbody.cl",type,count,notify,CL_ARGS); #else cl_environment_t *pEnv = clCreateEnvironmentFromBins(&gKernelBins, notify, CL_ARGS); #endif if (pEnv) { cl_uint i = 0, j = 0; cl_uint numIterations = (argc > 1?atoi(argv[1]):10); for (i = 0; i < numBodies; i++) { m[i] = frand() * ipow(10,rrand(4,27)); // masses should be 10^4 - 10^27 ("Earth heavy") frand4(a[i], 1, 3); frand4(v[i], 1, 2); frand4(p[i], 4, 8); t[i] = 0.001f; // 1 millisecond. } i = 0; for (j = 0; j < numIterations; j++) { nbodies(pEnv, m, a, v, p, t, numBodies); #if defined(DARWIN) printf("[%6u] p={%lf,%lf,%lf} v={%lf,%lf,%lf} a={%lf,%lf,%lf}\n", i, p[i][0], p[i][1], p[i][2], v[i][0], v[i][1], v[i][2], a[i][0], a[i][1], a[i][2]); #else printf("[%6u] p={%lf,%lf,%lf} v={%lf,%lf,%lf} a={%lf,%lf,%lf}\n", i, p[i].s[0], p[i].s[1], p[i].s[2], v[i].s[0], v[i].s[1], v[i].s[2], a[i].s[0], a[i].s[1], a[i].s[2]); #endif } clDeleteEnvironment(pEnv); cl_free(t); cl_free(m); cl_free(v); cl_free(a); cl_free(p); } return 0; }
double ipow(double x, int n) /* x**n. ought to be done by pow, but isn't always */ { double v; if (n <= 0) return 1; v = ipow(x, n/2); if (n % 2 == 0) return v * v; else return x * v * v; }
void ppGInvDecR (void* y, PrimeExponent pe, hDim_t lts, hDim_t rts, hInt_t q) { #ifdef DEBUG_MODE ASSERT (q==0); #endif hDim_t p = pe.prime; hShort_t e = pe.exponent; if (p != 2) { gInvDecR ((hInt_t*)y, lts*ipow(p,e-1), rts, p); } }
/* coefficients for spline of order >3 */ void splinen(float *c,float t,float *a,int n) { int i,k; float xn; memset((void *)c,0,(n+1)*sizeof(float)); for (k=0;k<=n+1;k++) { xn = ipow(t+(float)k,n); for (i=k;i<=n;i++) c[i] += a[i-k]*xn; } }
long sigma(long k, long* primes) { long* factors = pfactors(k, primes); long prod = 1; long i; for(i = 0; factors[i] != 0; i += 2) { long num = ipow(factors[i], factors[i+1]+1)-1; long den = factors[i]-1; prod *= num/den; } free(factors); return prod; }
void frand4(cl_float4 f, cl_int l, cl_int h) { #if 0 //defined(DARWIN) f[0] = frand() * ipow(10, rrand(l,h)); f[1] = frand() * ipow(10, rrand(l,h)); f[2] = frand() * ipow(10, rrand(l,h)); f[3] = frand() * ipow(10, rrand(l,h)); #else f.s[0] = frand() * ipow(10, rrand(l,h)); f.s[1] = frand() * ipow(10, rrand(l,h)); f.s[2] = frand() * ipow(10, rrand(l,h)); f.s[3] = frand() * ipow(10, rrand(l,h)); #endif }
/* * Populate Transition and Reinforcement Matrices for MDP class */ void populate(long a, long C, long G, long B, double prequest, double *pg, double *ctr, double *ecpi, long *rows, long *cols, double *values, double *valuesR) { long idx, S, s, g, aux; long *sa, *sc; double PI; // Auxiliary variables sa = (long*)malloc((C+1)*sizeof(long)); sc = (long*)malloc((C+1)*sizeof(long)); // Number of States of MDP S = ipow(B+1,C)*(G+1); idx = 0; // populate the matrices values, valuesR, rows and cols // Sparse matrix format: COO for (s = 0; s < S; s++) { getStateOfIndex(s,C,G,B,sa); for (g = 0; g < G+1; g++) { memcpy(sc,sa,C*sizeof(long)); sc[C] = g; if (g == 0) PI = 1-prequest; else PI = prequest*pg[g-1]; if ( (a < C) && (sa[C] > 0) && (sa[a] > 0) ) { rows[idx] = s; getIndexOfState(&cols[idx],C,G,B,sc); values[idx] = PI*(1-ctr[ (sa[C]-1)*(C) + a]); valuesR[s] = ecpi[ (sa[C]-1)*(C) + a]; idx++; sc[a] = sc[a]-1; rows[idx] = s; getIndexOfState(&cols[idx],C,G,B,sc); values[idx] = PI*ctr[ (sa[C]-1)*(C) +a]; idx++; } else { rows[idx] = s; getIndexOfState(&cols[idx],C,G,B,sc); values[idx] = PI; idx++; } } } free(sa); free(sc); }
double evaluatePoly(double *coef, int32_t **power, long nCoef, double *input, long nInputs) { double sum = 0, term; long iCoef, iInput; for (iCoef=0; iCoef<nCoef; iCoef++) { term = coef[iCoef]; for (iInput=0; iInput<nInputs; iInput++) term *= ipow(input[iInput], power[iInput][iCoef]); sum += term; } return sum; }
cl_int range_of_operator(cl_char *op, cl_uint n, cl_uint limit) { cl_int range; cl_uint p,q,r,s; cl_int max = 0, min = 0x7FFFFFFF; for (p = 0; p < 2; p++) { for (q = 0; q < n; q++) { for (r = 0; r < n; r++) { s = (p * n * n) + (q * n) + r; if (op[s] < min) min = op[s]; else if (op[s] > max) max = op[s]; } } } range = isqrt(ipow(abs(min)*limit,2) + ipow(max*limit,2)); return range; }
Cell *arith(Node **a, int n) /* a[0] + a[1], etc. also -a[0] */ { Awkfloat i, j = 0; double v; Cell *x, *y, *z; x = execute(a[0]); i = getfval(x); tempfree(x); if (n != UMINUS) { y = execute(a[1]); j = getfval(y); tempfree(y); } z = gettemp(); switch (n) { case ADD: i += j; break; case MINUS: i -= j; break; case MULT: i *= j; break; case DIVIDE: if (j == 0) ERROR "division by zero" FATAL; i /= j; break; case MOD: if (j == 0) ERROR "division by zero in mod" FATAL; modf(i/j, &v); i = i - j * v; break; case UMINUS: i = -i; break; case POWER: if (j >= 0 && modf(j, &v) == 0.0) /* pos integer exponent */ i = ipow(i, (int) j); else i = errcheck(pow(i, j), "pow"); break; default: /* can't happen */ ERROR "illegal arithmetic operator %d", n FATAL; } setfval(z, i); return(z); }
void computeChromaticTuneLimits(LINE_LIST *beamline) { long i, j, n, p; double c1, c2, c3, tuneValue[5], solution[2]; for (i=0; i<2; i++) { if (beamline->chromDeltaHalfRange<=0) { beamline->tuneChromUpper[i] = beamline->tuneChromLower[i] = beamline->tune[i]; } else { tuneValue[0] = beamline->tune[i]; /* polynomial coefficients */ c1 = beamline->chromaticity[i]; c2 = beamline->chrom2[i]/2.0; c3 = beamline->chrom3[i]/6.0; tuneValue[1] = beamline->tune[i] + beamline->chromDeltaHalfRange*c1 + sqr(beamline->chromDeltaHalfRange)*c2 + ipow(beamline->chromDeltaHalfRange, 3)*c3; tuneValue[2] = beamline->tune[i] - beamline->chromDeltaHalfRange*c1 + sqr(beamline->chromDeltaHalfRange)*c2 - ipow(beamline->chromDeltaHalfRange, 3)*c3; p = 3; /* find extrema */ n = solveQuadratic(3*c3, 2*c2, c1, solution); for (j=0; j<n; j++) { if (fabs(solution[j])>beamline->chromDeltaHalfRange) continue; tuneValue[p] = beamline->tune[i] + solution[j]*c1 + sqr(solution[j])*c2 + ipow(solution[j], 3)*c3; p += 1; } find_min_max(beamline->tuneChromLower+i, beamline->tuneChromUpper+i, tuneValue, p); } } }
//We can split this into a part for each l and just build the subspaces, and we already have the permutation matrix so msym_error_t findProjection(CharacterTable *ct, int sopsl, msym_symmetry_operation_t sops[sopsl], msym_permutation_t perm[sopsl], int l, msym_orbital_t *basis[2*l+1]){ msym_error_t ret = MSYM_SUCCESS; int kdim = ipow(3,l), setl = perm[0].p_length; double (*mkron)[kdim] = malloc(sizeof(double[kdim][kdim])); double (*mperm)[setl] = malloc(sizeof(double[setl][setl])); for(int m = 0; m < 2*l+1;m++){ permutationMatrix(&perm[m], mperm); } free(mperm); free(mkron); return ret; }
int main() { srand(time(NULL)); u32 results[powers][2]; printf("Benchmarking creation and search times...\n"); u32 i; for (i = 0; i < powers; i++) { printf("10^%u.. ", i+1); fflush(stdout); const u32 power = ipow(10, i+1); check(power, results[i][0], results[i][1]); } puts("\n"); for (i = 0; i < powers; i++) { const u32 power = ipow(10, i+1); printf("Using %u (10^%u) points, creation took %u us (%u ms)\n" "\tand 1M searches took %u us. (%.2f us/search)\n", power, i+1, results[i][0], results[i][0] / 1000, results[i][1], (float) results[i][1] / maxnum); } printf("\n\nProgression:\n"); for (i = 1; i < powers; i++) { const float c = (float) results[i][0] / results[i - 1][0]; const float s = (float) results[i][1] / results[i - 1][1]; printf("Creation %.2fx, search %.2fx\n", c, s); } return 0; }