void runSuccess() { floorl(1.0L); floorl(0.0L); floorl(43.56L); floorl(-2.5L); floorl(anylongdouble()); }
static int location_tag (cxml_handler_t* const _h, cxml_tag_t * const tag) { int rc = 0; if (cxml_tag_is_open(tag)){ int32_t lat, lon; long double d; cert_cxml_handler_t * h = (cert_cxml_handler_t *)_h; const char * v = cxml_tag_attr_value(tag, "latitude"); if(v == NULL){ fprintf(stderr, "ERROR: Latitude shall be specified for location.\n"); return -1; } d = strtold(v, NULL); if (d <= 90.0 && d >= -90.0) d *= 10000000.0; // degree lat = (int32_t)floorl(d+_refLat); v = cxml_tag_attr_value(tag, "longitude"); if(v == NULL){ fprintf(stderr, "ERROR: Longitude shall be specified for location.\n"); return -1; } d = strtold(v, NULL); if (d <= 180.0 && d >= -180.0) d *= 10000000.0; // degree lon = (int32_t)floorl(d + _refLon); cint32_write(lat, &h->ptr, h->end, &rc); cint32_write(lon, &h->ptr, h->end, &rc); } return rc; }
int IsFib(long long T) { double root5 = sqrt(5); double phi = (1 + root5) / 2; long long u; long long idx; idx = (long) floorl( logl(T*root5) / logl(phi) + 0.5 ); u = (long) floorl( powl(phi, idx)/root5 + 0.5); return (u == T); }
long double private_nearbyintl(long double x) { long double x1; x1 = - floorl(-x + 0.5); x = floorl(x + 0.5); if (x == x1) return(x); else { /* FIXME: we should really test for floorl, also C99. But FreeBSD 7.x does have it, but not nearbyintl */ if (x/2.0 == floorl(x/2.0)) return(x); else return(x1); } }
/*------------------------------------------------------------------------------ Write angle into string in appropriate format. In particular, this routine supports the hms dms format for RA & Dec. All angles written by mangle go through this routine. Input: angle = angle. unit = format in which to write angle; this is only used to decide the format, not to rescale the angle, which remains unchanged; the 'h' unit signifies hms(RA) and dms(Dec); otherwise angle is written to str as a long double. precision = number of digits after decimal point in output angles. Output: str = pointer to string containing the angle. str_len = length of string. */ void wrangle(long double angle, char unit, int precision, size_t str_len, char str[/*str_len*/]) { /* default number of significant digits */ #define DIGITS 15 char sign; int hour, min; int width; long double a, sec; if (unit == 'h') { sign = (angle < 0.)? '-' : ' '; a = fabsl(angle); hour = floorl(a); a = (a - hour) * 60.; min = floorl(a); a = (a - min) * 60.; sec = a; if (precision < 0) precision = DIGITS - 7; width = precision + 3; if (precision == 0) width--; snprintf(str, str_len, "%c%02d %02d %0*.*Lf", sign, hour, min, width, precision, sec); } else { switch (unit) { case 'r': /* radians */ default: if (precision < 0) precision = DIGITS - 1; width = precision + 3; break; case 'd': /* degrees */ case '°': if (precision < 0) precision = DIGITS - 3; width = precision + 5; break; case 'm': /* arcminutes */ case '\'': case '´': if (precision < 0) precision = DIGITS - 5; width = precision + 7; break; case 's': /* arcseconds */ case '"': case '¨': if (precision < 0) precision = DIGITS - 7; width = precision + 9; break; } if (precision == 0) width--; snprintf(str, str_len, "%*.*Lf", width, precision, angle); } }
unsigned long BloomFilter::hash2(const Key& key) { unsigned long hash = 0; for (unsigned i = 0; i < key.length(); i++) { hash = key.c_str()[i] + (hash << 6) + (hash << 16) - hash; } long double d_hash = (long double)hash; d_hash *= (0.5 * (sqrtl(5) - 1)); d_hash = d_hash / 10.0 - floorl(d_hash / 10.0); d_hash *= (double)m_length; return (unsigned long)floorl(d_hash); }
/* * If the line between (OT1, NT1) and (OT2, NT2) is a straight line * and (OT3, NT3) is on that line, * then (NT2 - NT1) / (OT2 - OT2) = (NT3 - NT1) / (OT3 - OT1) and * then (OT3 - OT1) * (NT2 - NT1) / (OT2 - OT2) = (NT3 - NT1) and * then NT1 + (OT3 - OT1) * (NT2 - NT1) / (OT2 - OT2) = NT3 and * then NT3 = NT1 + (OT3 - OT1) * (NT2 - NT1) / (OT2 - OT2) and * thus NT3 = NT1 + (OT3 - OT1) * (NT2 - NT1) / (OT2 - OT1) * or NT3 = NT1 + (OT3 - OT1) * ( deltaNT12 / deltaOT12) * * All the things you come up when waiting for the train to come... */ static void calcNT3(nstime_t *OT1, nstime_t *OT3, nstime_t *NT1, nstime_t *NT3, nstime_t *deltaOT, nstime_t *deltaNT) { long double fnt, fot, f, secs, nsecs; fnt = (long double)deltaNT->secs + (deltaNT->nsecs / 1000000000.0L); fot = (long double)deltaOT->secs + (deltaOT->nsecs / 1000000000.0L); f = fnt / fot; nstime_copy(NT3, OT3); nstime_subtract(NT3, OT1); secs = f * (long double)NT3->secs; nsecs = f * (long double)NT3->nsecs; nsecs += (secs - floorl(secs)) * 1000000000.0L; while (nsecs > 1000000000L) { secs += 1; nsecs -= 1000000000L; } while (nsecs < 0) { secs -= 1; nsecs += 1000000000L; } NT3->secs = (time_t)secs; NT3->nsecs = (int)nsecs; nstime_add(NT3, NT1); }
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; }
void test_floor() { static_assert((std::is_same<decltype(floor((double)0)), double>::value), ""); static_assert((std::is_same<decltype(floorf(0)), float>::value), ""); static_assert((std::is_same<decltype(floorl(0)), long double>::value), ""); assert(floor(1) == 1); }
/** * Function to restore the presets saved in persistent storage into the list. */ void presets_restore(void){ presets_clear(); if (!persist_exists(STORAGE_PRESET_START)) return; int block = 0; PresetBlock* presetBlock = malloc(sizeof(PresetBlock)); persist_read_data(STORAGE_PRESET_START, presetBlock, sizeof(PresetBlock)); uint8_t preset_count = presetBlock->count; int save_time = presetBlock->time; int now = time(NULL); int seconds_elapsed = now-save_time; int minutes_elapse = (int)(floorl(seconds_elapsed / 60)); for (int i = 0; i < preset_count; i++){ if (i > 0 && i % PRESET_BLOCK_SIZE == 0){ block += 1; free(presetBlock); presetBlock = malloc(sizeof(PresetBlock)); persist_read_data(STORAGE_PRESET_START + block, presetBlock, sizeof(PresetBlock)); } Preset *preset = preset_clone(&presetBlock->presets[i % PRESET_BLOCK_SIZE]); preset->eta -= minutes_elapse; if (preset->eta <= 0) preset->eta = PRESET_REFRESHING_ETA; presets_add(preset); } free(presetBlock); send_all_eta_req(); return; }
long double expm1l(long double x) { long double px, qx, xx; int k; /* Overflow. */ if (x > MAXLOGL) return huge*huge; /* overflow */ if (x == 0.0) return x; /* Minimum value.*/ if (x < minarg) return -1.0; xx = C1 + C2; /* Express x = ln 2 (k + remainder), remainder not exceeding 1/2. */ px = floorl(0.5 + x / xx); k = px; /* remainder times ln 2 */ x -= px * C1; x -= px * C2; /* Approximate exp(remainder ln 2).*/ px = (((( P4 * x + P3) * x + P2) * x + P1) * x + P0) * x; qx = (((( x + Q4) * x + Q3) * x + Q2) * x + Q1) * x + Q0; xx = x * x; qx = x + (0.5 * xx + xx * px / qx); /* exp(x) = exp(k ln 2) exp(remainder ln 2) = 2^k exp(remainder ln 2). We have qx = exp(remainder ln 2) - 1, so exp(x) - 1 = 2^k (qx + 1) - 1 = 2^k qx + 2^k - 1. */ px = scalbnl(1.0, k); x = px * qx + (px - 1.0); return x; }
void Round (Token ** Pila) { Token *Operando = EntornoEjecucion_BuscaSimbolo (*Pila); if (Buzon.GetHuboError ()) return; if (NoEsReal (Operando)) { BorrarTokenSiEsVariable (Operando); return; } long double ValorDominio = Operando->GetDatoReal (); BorrarTokenSiEsVariable (Operando); long double ValorRetorno = floorl (fabsl (ValorDominio) + 0.5L) * (ValorDominio < 0 ? (-1.0L) : (1.0L)); Token *TokenRetorno = ConsigueToken (ValorRetorno); if (Buzon.GetHuboError ()) return; delete Desapila (Pila); Apila (Pila, TokenRetorno); return; }
long double expl(long double x) { long double px, xx; int n; if( x > MAXLOGL) return (huge*huge); /* overflow */ if( x < MINLOGL ) return (twom10000*twom10000); /* underflow */ /* Express e**x = e**g 2**n * = e**g e**( n loge(2) ) * = e**( g + n loge(2) ) */ px = floorl( LOG2EL * x + 0.5L ); /* floor() truncates toward -infinity. */ n = px; x += px * C1; x += px * C2; /* rational approximation for exponential * of the fractional part: * e**x = 1 + 2x P(x**2)/( Q(x**2) - P(x**2) ) */ xx = x * x; px = x * __polevll( xx, P, 4 ); xx = __polevll( xx, Q, 5 ); x = px/( xx - px ); x = 1.0L + x + x; x = ldexpl( x, n ); return(x); }
long double FindXYgivenD (long double D) { long double maxx = 0; long double miny = 0; long double y; for ( y = 1 ; y < D; y++) { long double x = Diophanite(D, y); //if ((x < (x+.001)) && (x> (x-.001))) { if (floorl(x) == x) { if (maxx < x) { maxx = x; miny = y; } } //if } // for if (maxx == 0) printf("None found for D= %0.0Lf\n", D); else printf("%0.0Lf^2 - %0.0Lf * %0.0Lf^2 = 1\n", maxx, D, miny); return maxx; } // FindXYgivenD
long double expl(long double x) { long double px, xx; int k; if (isnan(x)) return x; if (x > 11356.5234062941439488L) /* x > ln(2^16384 - 0.5) */ return x * 0x1p16383L; if (x < -11399.4985314888605581L) /* x < ln(2^-16446) */ return -0x1p-16445L/x; /* Express e**x = e**f 2**k * = e**(f + k ln(2)) */ px = floorl(LOG2E * x + 0.5); k = px; x -= px * LN2HI; x -= px * LN2LO; /* rational approximation of the fractional part: * e**x = 1 + 2x P(x**2)/(Q(x**2) - x P(x**2)) */ xx = x * x; px = x * __polevll(xx, P, 2); x = px/(__polevll(xx, Q, 3) - px); x = 1.0 + 2.0 * x; return scalbnl(x, k); }
int divides(long double first, long double second){ long double r = second/first; if (floorl (r) == r) return 1; else return 0; }
static int _refPoint_option(const copt_t * opt, const char * option, const copt_value_t * value) { char * e; long double lat, lon; lat = strtold(value->v_str, &e); if (*e == ':'){ lon = strtold(e + 1, &e); if (*e == 0){ if (lat <= 90.0 && lat >= -90.0) lat *= 10000000.0; // degree _refLat = (int32_t)floorl(lat); if (lon <= 180.0 && lon >= -180.0) lon *= 10000000.0; // degree _refLon = (int32_t)floorl(lon); return 0; } } return -1; }
/* Find a multiple of 1/NXT that is within 1/NXT of x. */ static long double reducl(long double x) { long double t; t = x * NXT; t = floorl(t); t = t / NXT; return t; }
void testValues() { f = 2; long double result; floorl(anylongdouble()); //@ assert f == 2; //@ assert vacuous: \false; }
std::string Stopwatch::ToHoursString() const { const long double hours = roundl(Seconds() / 60.0)/60.0; std::stringstream str; if(hours >= 10.0) str << roundl(hours) << 'h'; else str << floorl(hours) << 'h' << (hours*60.0) << 'm'; return str.str(); }
std::string Stopwatch::ToMinutesString() const { const long double mins = roundl(Seconds())/60.0; std::stringstream str; if(mins >= 10.0) str << roundl(mins) << " min"; else str << floorl(mins) << 'm' << fmod(mins*60.0,60.0) << 's'; return str.str(); }
long double fmodl (long double x, long double y) { if (y == 0.0L) return 0.0L; /* Need to check that the result has the same sign as x and magnitude less than the magnitude of y. */ return x - floorl (x / y) * y; }
std::string Stopwatch::ToDaysString() const { const long double days = roundl(Seconds() / (60.0*60.0))/24.0; std::stringstream str; if(days >= 10.0) str << roundl(days) << " days"; else str << floorl(days) << 'd' << (days*24.0) << 'h'; return str.str(); }
void Scene::findBuildingFields() { TerrainType** map = _landscape.getMap(); for(int i = 0; i < FIELD_SIZE; i++) { for(int j = 0; j < FIELD_SIZE; j++) { if(map[i][j] != BUILDING) { continue; } int x = floorl(i); int z = floorl(j); int idx = z*FIELD_SIZE + x; _buildingFields.push_back(idx); } } }
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; } }
inline long double MathTrait<long double>::round( const long double val ) { if( val >= 0.0l ) { return floorl( val + 0.5l ) ; } else { return ceill( val - 0.5l ) ; } }
long double roundl(long double x) { long double t; if (!isfinite(x)) return (x); if (x >= 0.0) { t = floorl(x); if (t - x <= -0.5) t += 1.0; return (t); } else { t = floorl(-x); if (t + x <= -0.5) t += 1.0; return (-t); } }
long double __lgammal_r(long double x, int *signgamp) { long double y = __ieee754_lgammal_r(x,signgamp); if(__builtin_expect(!isfinite(y), 0) && isfinite(x) && _LIB_VERSION != _IEEE_) return __kernel_standard(x, x, floorl(x)==x&&x<=0.0 ? 215 /* lgamma pole */ : 214); /* lgamma overflow */ return y; }
void print_double(void *elem, void *fileout){ long double k, i, j; long double x; k = *((long double*)elem); x = (1 + sqrtl(1 + 8 * (k-1))) / 2; i = floorl(x) + 1; j = k - ( (i-1)*1.0 * (i-2) ) /2; //printf("x: %Lf\n i: %0.0Lf j: %0.0Lf\n", x, i, j); fprintf((FILE*)fileout, "%0.0Lf %0.0Lf\n", i-1, j-1); }
long double LGFUNC (__lgammal) (long double x) { long double y = CALL_LGAMMA (long double, __ieee754_lgammal_r, x); if(__builtin_expect(!isfinite(y), 0) && isfinite(x) && _LIB_VERSION != _IEEE_) return __kernel_standard_l(x, x, floorl(x)==x&&x<=0.0L ? 215 /* lgamma pole */ : 214); /* lgamma overflow */ return y; }