long double probability_functions::power_law_inverse(long double probability) { long double d0, rho, lambda; #if D0_1 d0 = 1; #endif #if RHO_0_5 rho = 0.5; #endif #if RHO_0_7 rho = 0.7; #endif #if RHO_0_9 rho = 0.9; #endif #if LAMBDA_0_75 lambda = 0.75; #endif #if LAMBDA_1 lambda = 1; #endif #if LAMBDA_1_25 lambda = 1.25; #endif //return (powl(rho / probability, 1.0 / lambda) - d0) / 10; return powl(rho / probability, 1 / lambda) - d0; return powl(rho / (probability + 0.1), 1 / lambda) - d0; }
int main(void) { int i; long double j, x, y, z; y = 1.0; x = -5.5; j = 1.0; printf( " i z/100000.0 1/y \n\n" ); for(i=1; i<=25; i++) { j *= i; z = floor( powl(-1.0, i) + ((powl(-x, i) *(100000.0/j))) + ((2.0/powl(((-x)*(-x)), 2.0*i)) *((2.0/100000.0)/(2.0/j)))); y += ( z/100000.0 ); printf( " %d %'.16Lf %'.16Lf \n", i, z/100000.0, 1/y ); } printf( " real value of exp(-5.5) = %'.16Lf\n", (long double) exp(-5.5) ); return 0; }
static long double stirf(long double x) { long double y, w, v; w = 1.0L/x; /* For large x, use rational coefficients from the analytical expansion. */ if (x > 1024.0L) w = (((((6.97281375836585777429E-5L * w + 7.84039221720066627474E-4L) * w - 2.29472093621399176955E-4L) * w - 2.68132716049382716049E-3L) * w + 3.47222222222222222222E-3L) * w + 8.33333333333333333333E-2L) * w + 1.0L; else w = 1.0L + w * polevll( w, STIR, 8 ); y = expl(x); if (x > MAXSTIR) { /* Avoid overflow in pow() */ v = powl(x, 0.5L * x - 0.25L); y = v * (v / y); } else { y = powl(x, x - 0.5L) / y; } y = SQTPI * y * w; return (y); }
void updateBTX(pulsar *psr,double val,double err,int pos,int k) { if (pos==param_fb) { psr->param[param_fb].val[k] += (val/powl(1.0e7,k+1)); psr->param[param_fb].err[k] = err/powl(1.0e7,k+1); } else if (pos==param_a1 || pos==param_ecc || pos==param_t0 || pos==param_gamma || pos==param_edot) { psr->param[pos].val[0] += val; psr->param[pos].err[0] = err; } else if (pos==param_om) { psr->param[pos].val[0] += val*180.0/M_PI; psr->param[pos].err[0] = err*180.0/M_PI; } else if (pos==param_pbdot) { psr->param[pos].val[0] += val; psr->param[pos].err[0] = err; } else if (pos==param_omdot) { psr->param[pos].val[0] += val*(SECDAY*365.25)*180.0/M_PI; psr->param[pos].err[0] = err*(SECDAY*365.25)*180.0/M_PI; } else if (pos==param_a1dot) { psr->param[pos].val[0] += val; psr->param[pos].err[0] = err; } }
long double cmrpirpj(vec rpi, vec rpj) { long double cmij; cmij = (powl((rpi[0]-rpj[0]),2)+powl((rpi[1]-rpj[1]),2)+powl((rpi[2]-rpj[2]),2))/2.; return(cmij); }
ull* productFib(ull prod) { ull *out = malloc(3 * sizeof(ull*)); ull isfib = 1; long double golden = 1.6180339887498948482; long double srfive = 2.2360679774997896964; long double p = (long double)prod; long double n, m, r, t; n = roundl(sqrtl(p / golden)); m = p / n; r = fmodl(p, n); if (r > 0) { isfib = 0; t = floorl(logl(n * srfive) / logl(golden)) + 1; n = roundl(powl(golden, t) / srfive); m = roundl(powl(golden, t + 1) / srfive); } out[0] = (ull)n; out[1] = (ull)m; out[2] = isfib; return out; }
static int do_test (void) { int result = 0; #ifndef NO_LONG_DOUBLE # if LDBL_MANT_DIG == 64 { long double x = 1e-20; union ieee854_long_double u; u.ieee.mantissa0 = 1; u.ieee.mantissa1 = 1; u.ieee.exponent = 0; u.ieee.negative = 0; (void) powl (0.2, u.d); x = powl (x, 1.5); if (fabsl (x - 1e-30) > 1e-10) { printf ("powl (1e-20, 1.5): wrong result: %Lg\n", x); result = 1; } } # endif #endif return result; }
int pixel_start(int res, char scheme){ //int res1; //long double res_d; if(res<0){ fprintf(stderr, "error in pixel_start: %d not a valid resolution.\n", res); return(-1); } if(scheme=='s'){ return ((int)((powl(4,res)-1)/3)); } else if(scheme=='d'){ //res_d = (long double)(logl((long double)res)/logl(2.0))+1; //res1 = (int)(res_d + 0.1); //printf("pixel_start: res = %d\n", res); if(res==0) return(0); else if(res==1) return(1); else return (468*(((int)powl(4,res-1)-4)/12)+118); } else{ fprintf(stderr, "error in pixel_start: pixel scheme %c not recognized.\n", scheme); return(-1); } }
void run_triangle(unsigned long max_bits, double ratio) { int max_iter = (int) ceil(log((double) max_bits) / log(ratio)); unsigned long last_length = 0; unsigned long i; for (i = 0; i <= max_iter; i++) { unsigned long length = (unsigned long) floor(powl(ratio, i)); if (length != last_length) { last_length = length; unsigned long last_bits = 0; unsigned long j; for (j = 0; j <= max_iter; j++) { unsigned long bits = (unsigned long) floor(powl(ratio, j)); if (bits != last_bits) { last_bits = bits; if (bits * length < max_bits) prof2d_sample(length, bits, NULL); } } } } }
int main() { char base[5] = {'m','a','n','k','u'}; int output[100]; int c[100],test; long long n,t=0,temp=0; int i=0; scanf("%d",&test); while(test--) { temp=0;i=0; scanf("%lld",&n); while((temp + powl(5,i)) <= n) { temp = temp+powl(5,i); output[i] = 0; i++; } n = n-temp; t=0; while(n != 0) { output[t] = n%5; n = n/5; t++; } for(t=i-1;t>=0;t--) printf("%c",base[output[t]]); printf("\n"); } return 0; }
static long double P(long double mu, long double sigma, long double x) { long double tmp = 1 / (sigma * sqrtl(2.0 * M_PIl)); long double up = -powl(x-mu, 2) / (2 * powl(sigma, 2)); tmp *= expl(up); return tmp; }
void get_MS5637_temp_and_pressure(double* temperature_ptr, double* pressure_ptr, uint8_t osr_d1, uint8_t osr_d2) { uint32_t raw_temperature = 0; uint32_t raw_pressure = 0; double dt, offset, sens, t2, offset2, sens2; double temperature_buf; raw_pressure = I2C_MS5637_Read(osr_d1); raw_temperature = I2C_MS5637_Read(osr_d2); dt = raw_temperature - prom_data[5]*pow(2,8); // calculate temperature difference from reference offset = prom_data[2]*pow(2, 17) + dt*prom_data[4]/pow(2,6); sens = prom_data[1]*pow(2,16) + (dt*prom_data[3])/pow(2,7); temperature_buf = (2000 + (dt*prom_data[6])/pow(2, 23))/100; // First-order Temperature in degrees Centigrade // Second order corrections if(temperature_buf >= 20) { t2 = 5*dt*dt/powl(2, 38); // correction for high temperatures offset2 = 0; sens2 = 0; } if(temperature_buf < 20) // correction for low temperature { t2 = 3*dt*dt/powl(2, 33); offset2 = 61*(temperature_buf - 2000)*(temperature_buf - 2000)/16; sens2 = 29*(temperature_buf - 2000)*(temperature_buf - 2000)/16; } if(temperature_buf < -15) // correction for very low temperature { offset2 = offset2 + 17*(temperature_buf + 1500)*(temperature_buf + 1500); sens2 = sens2 + 9*(temperature_buf + 1500)*(temperature_buf + 1500); } if((temperature_buf < -50) || (temperature_buf > 100)) { // uint8_t reset_ctr = 0; // for(reset_ctr = 0; reset_ctr < 7; reset_ctr++) // { // prom_data[reset_ctr] = 0; // } // setup_imu(); } else { // End of second order corrections offset = offset - offset2; sens = sens - sens2; if(xSemaphoreTake(xSemaphore_pressure_temperature_mutex_handle, 0)) { *temperature_ptr = temperature_buf - t2; *pressure_ptr = (((raw_pressure*sens)/pow(2, 21) - offset)/pow(2, 15))/100; // Pressure in mbar or kPa xSemaphoreGive( xSemaphore_pressure_temperature_mutex_handle ); xSemaphoreGive( xSemaphore_pressure_temperature_mutex_handle ); } } }
double t2FitFunc_dmsinusoids(pulsar *psr, int ipsr ,double x ,int ipos ,param_label label,int k){ if (label==param_dm_sin1yr){ return 1.0/(DM_CONST*powl(psr[ipsr].obsn[ipos].freqSSB/1.0e6,2))*sin(2*M_PI/(365.25)*(psr[ipsr].obsn[ipos].sat - psr[ipsr].param[param_dmepoch].val[0])); } else if (label==param_dm_cos1yr) { return 1.0/(DM_CONST*powl(psr[ipsr].obsn[ipos].freqSSB/1.0e6,2))*cos(2*M_PI/(365.25)*(psr[ipsr].obsn[ipos].sat - psr[ipsr].param[param_dmepoch].val[0])); } else { logerr("Called dmsinusoids without dmsin1yr or dmcos1yr"); return 0; } }
static long double _parcJSONValue_GetNumber(const PARCJSONValue *value) { long double fraction = value->value.number.fraction / powl(10.0, value->value.number.fractionLog10); long double number = (long double) value->value.number.sign * ((long double) value->value.number.whole + fraction); long double result = number * powl(10.0, (long double) value->value.number.exponent); return result; }
int getAnswer(int n, int p) { long double k = 2; int val = powl(k,(long double)(p-1)/2)%p; printf("%d",val); printf("%d",k); long double x = powl((k + sqrt(k^2-n)),(p+1)/2); return (int)x; }
long double TSolver::gcalc(const char f,const long double a,const long double b,const long double step) //calculates function { #define ain(x) (a-step<=x && a+step>=x) #define bin(x) (b-step<=x && b+step>=x) #define angin(x) (torad(a)-step<x && torad(a)+step>x) switch (f) {case '+' : return a+b; case '-' : return a-b; case '*' : return a*b; case '/' : if (bin(0)) {Err=E_DEV_ZERO;return 0;};return a/b; case '!' : if (floorl(a)!=a) {Err=E_ARG;return 0;}return factor(a); case '_' : return -a; case cpi : return M_PI; case cx : return X; case fexp : return exp(a); case fln : if (a<0) {Err=E_ARG;return 0;}return logl(a); case flog : if (a<0) {Err=E_ARG;return 0;}return log10l(a); case flogn : if (a<0) {Err=E_ARG;return 0;}return log(a)/log(b); case '^': case f_op_pow: case fpow : if (a<0 && b<1 && b>0 && (!fmodl(b,2))) {Err=E_ARG;return 0;}return powl(a,b); case fsqr : return a*a; case f_op_root: case froot : if (a<0 && (!fmodl(b,2))){Err=E_ARG;return 0;} return (a>0 || (!fmodl(b,2)))?powl(a,1/b):-powl(-a,1/b); case fsqrt : if (a<0) {Err=E_ARG;return 0;}return sqrtl(a); case f_abs : return fabsl(a); case fsin : return sinl(a); case fcos : return cosl(a); case ftan : if (angin(M_PI_2) || angin(M_PI_2+M_PI)) {Err=E_ARG;return 0;} return tanl(a); case fctan : if (angin(0) || angin(M_PI)) {Err=E_ARG;return 0;} return 1/tanl(a); case fsin+ARC : if (fabsl(a)>1) {Err=E_ARG;return 0;} return asinl(a); case fcos+ARC : if (fabsl(a)>1) {Err=E_ARG;return 0;} return acosl(a); case ftan+ARC : return atanl(a); case fctan+ARC: return atanl(1/a); case fsin+HYP : return sinhl(a); case fcos+HYP : return coshl(a); case ftan+HYP : return tanhl(a); case fctan+HYP : return 1/tanhl(a); #ifndef _OLD_ case fsin+HYP+ARC : return asinhl(a); case fcos+HYP+ARC : return acoshl(a); case ftan+HYP+ARC : if (fabsl(a)>=1) {Err=E_ARG;return 0;} return atanhl(a); case fctan+HYP+ARC : if (angin(0)) {Err=E_ARG;return 0;} return atanhl(1/a); #endif default: return 0; } }
void LineAnimation::initValues() { //IMEDIATELY AFTER KNOWING THE CONTROL POINTS WE CALCULATE THE OVERALL DESTANCE OF THE ANIMATION total_delta_x = controlPoints->second->at(X) - controlPoints->first->at(X); total_delta_y = controlPoints->second->at(Y) - controlPoints->first->at(Y); total_delta_z = controlPoints->second->at(Z) - controlPoints->first->at(Z); double dist_x = (double) powl(total_delta_x, 2.0); double dist_y = (double) powl(total_delta_y, 2.0); double dist_z = (double) powl(total_delta_z, 2.0); total_animation_distance = (double) sqrtl(dist_x + dist_y + dist_z); }
long double B(long double x) { long double ret; if (fabsl(x)>1e-40) { ret=x/(expl(x)-1.0); //From mathworld and wikipidia }else { ret=1-x/2.0+powl(x,2.0)/12.0-powl(x,4.0)/720.0+powl(x,6.0)/30240.0; } return ret; }
//Taken from mathworld and wikipidia long double dB(long double x) { long double ret; if (fabsl(x)>1e-40) { ret=(expl(x)-1.0-x*expl(x))/(expl(x)-1)/(expl(x)-1); } else { ret= -1.0/2.0+x/6.0-powl(x,3.0)/180.0+powl(x,5.0)/5040; } return ret; }
int main() { char i, isPosExist, isAddOverflow, isMulOverflow; long k = 0, a, b, m, y, z; scanf("%ld %ld\n%ld\n", &a, &b, &m); for (i = 63; i >= 0; i--) { isPosExist = ((long) powl(2, i) & b) == (long) powl(2, i); isMulOverflow = k << 1 < k; z = isMulOverflow ? (k % m) * (2 % m) : k * 2; y = a * isPosExist; isAddOverflow = (z * y) < y && (z * y) < z; k = isAddOverflow ? (z % m) + (y % m) : z + y; } printf("%li", k % m); return 0; }
long double complex CLANG_PORT_DECL(cpowl) (long double complex X, long double complex Y) { long double complex Res; long double i; long double r = hypotl (__real__ X, __imag__ X); if (r == 0.0L) { __real__ Res = __imag__ Res = 0.0L; } else { long double rho; long double theta; i = cargl (X); theta = i * __real__ Y; if (__imag__ Y == 0.0L) /* This gives slightly more accurate results in these cases. */ rho = powl (r, __real__ Y); else { r = logl (r); /* rearrangement of cexp(X * clog(Y)) */ theta += r * __imag__ Y; rho = expl (r * __real__ Y - i * __imag__ Y); } __real__ Res = rho * cosl (theta); __imag__ Res = rho * sinl (theta); } return Res; }
/* * Bruce Lindbloom, "Spectral Power Distribution of a Blackbody Radiator" * http://www.brucelindbloom.com/Eqn_Blackbody.html */ static double spd_blackbody(unsigned long int wavelength, double TempK) { // convert wavelength from nm to m const long double lambda = (double)wavelength * 1e-9; /* * these 2 constants were computed using following Sage code: * * (from http://physics.nist.gov/cgi-bin/cuu/Value?h) * h = 6.62606957 * 10^-34 # Planck * c= 299792458 # speed of light in vacuum * k = 1.3806488 * 10^-23 # Boltzmann * * c_1 = 2 * pi * h * c^2 * c_2 = h * c / k * * print 'c_1 = ', c_1, ' ~= ', RealField(128)(c_1) * print 'c_2 = ', c_2, ' ~= ', RealField(128)(c_2) */ #define c1 3.7417715246641281639549488324352159753e-16L #define c2 0.014387769599838156481252937624049081933L return (double)(c1 / (powl(lambda, 5) * (expl(c2 / (lambda * TempK)) - 1.0L))); #undef c2 #undef c1 }
/** * Computes bessel I function of zero order applying the formula * * @param [in] x Bessel function argument * @param [in] tol Tolerance * * @return value */ long double bessi0_exact(long double x, long double tol){ // Return value and current long double acum, term; // Iterator register uint_fast64_t i; uintmax_t factorial=1; // Initialization acum = 1 ; term = 1 ; i = 1; // While last computed term is greater than given tolerance while( term > tol ){ factorial*=i; // Update factorial // Compute term term = powl(x/2.0,2*i) / (factorial*factorial); if(!isfinite(term)) break; acum+=term; i++; } return acum; }
bool Word::TryParseInt(int* outInt) const { int result = 0; if (_backing[0] > 57 || _backing[0] < 48) { *outInt = 0; return false; } result += _backing[_length - 1] - 48; for (int i = 1; i < _length; ++i) { if (_backing[i] > 57 || _backing[i] < 48) { *outInt = 0; return false; } result += (_backing[_length - 1 - i] - 48) * static_cast<int>(powl(10, i)); } *outInt = result; return true; }
RationalNumber operator ^ (const RationalNumber& B) const throw(std::invalid_argument) { if (!isFraction() || !B.isInteger()) { return RationalNumber(powl(getRealNumber(), B.getRealNumber())); } RationalNumber S(1, 1); RationalNumber A = *this; long long n = B.numerator; if (n < 0) { A = RationalNumber(1, 1) / A; n = -n; } while (n) { if (n & 1) { S = S * A; } A = A * A; n >>= 1; } return S; }
int ReplayGainReader_init(replaygain_ReplayGainReader *self, PyObject *args, PyObject *kwds) { self->pcmreader = NULL; self->channels = array_ia_new(); self->white_noise = NULL; self->audiotools_pcm = NULL; double replaygain; double peak; if (!PyArg_ParseTuple(args, "O&dd", pcmreader_converter, &(self->pcmreader), &(replaygain), &(peak))) return -1; if ((self->white_noise = open_dither()) == NULL) return -1; if ((self->audiotools_pcm = open_audiotools_pcm()) == NULL) return -1; self->multiplier = powl(10.0l, replaygain / 20.0l); if (self->multiplier > 1.0l) self->multiplier = 1.0l / peak; return 0; }
/* ?? 把n分解成所有素数的乘积,然后求ln(primt),并用数组保存起来,可能会更快 ?? */ long double ln_n(int n) { int lg_max = lg(n); long double ex = powl(2.0, lg_max); long double x = n / ex; return lg_max * M_LN2 + lnx(x, K); }
std::string fixed::ToString() const { std::stringstream stream; stream << m_num; std::string str = stream.str(); if ((str.length() != m_precision) && ((m_num / (unsigned long int)powl(10.0, m_precision)) == 0)) { // this handles the case where a fixed has no integer part (like 0.00003) // In this case, m_num is stored as 3, and is converted the same way // add the leading zeros: str.insert(0, std::string(m_precision, '0')); } if (str.length() - m_precision == 0) str.insert(0, "0."); // we want a leading 0 if there is no integer part to this fixed else if (m_precision != 0) str.insert(str.length() - m_precision, "."); if (!m_positive && (str.length() - m_precision != 0)) // don't add a "-" if we're a 0 number! str.insert(0, "-"); return str; }
static TACommandVerdict powl_cmd(TAThread thread,TAInputStream stream) { long double x, y, res; // Prepare x = readLongDouble(&stream); y = readLongDouble(&stream); errno = 0; START_TARGET_OPERATION(thread); // Execute res = powl(x, y); END_TARGET_OPERATION(thread); // Response writeLongDouble(thread, res); writeInt(thread, errno); sendResponse(thread); return taDefaultVerdict; }
static Result XXX_PushOpr(Stack *sopr, Stack *sval, int opr) { Result res = R_SUCCE; long double tmp; long double *ans; while (!SEmpty(sopr) && XXX_ShouldPop(*STopInt(sopr), opr)) { switch (SPopInt(sopr)) { case OPR_TRM: return R_ITRNL; case BIN_ADD: XXXPO_EVOB(*ans += tmp); case BIN_SUB: XXXPO_EVOB(*ans -= tmp); case BIN_MUL: XXXPO_EVOB(*ans *= tmp); case BIN_DIV: XXXPO_EVOB(*ans /= tmp); case BIN_MOD: XXXPO_EVOB(*ans = fmodl(*ans, tmp)); case BIN_PWR: XXXPO_EVOB(*ans = powl(*ans, tmp)); case UNA_PLS: XXXPO_EVOU(); case UNA_MNS: XXXPO_EVOU(*ans = -*ans); default: return R_ITRNL; } if ((res = RMathType(*ans))) return ERR(res); } if (SPushInt(sopr, opr)) return R_ITRNL; return R_SUCCE; }