double GlidePolar::SpeedToFly(const AircraftState &state, const GlideResult &solution, const bool block_stf) const { assert(IsValid()); double V_stf; const auto g_scaling = block_stf ? 1. : sqrt(fabs(state.g_load)); if (!block_stf && (state.netto_vario > mc + Smin)) { // stop to climb V_stf = Vmin; } else { const auto head_wind = !positive(GetMC()) && solution.IsDefined() ? solution.head_wind : 0.; const auto stf_sink_rate = block_stf ? 0. : -state.netto_vario; GlidePolarSpeedToFly gp_stf(*this, stf_sink_rate, head_wind, Vmin, Vmax); V_stf = gp_stf.solve(Vmax); } return std::max(Vmin, V_stf * g_scaling); }
fixed GlidePolar::SpeedToFly(const AircraftState &state, const GlideResult &solution, const bool block_stf) const { fixed V_stf; const fixed g_scaling (block_stf ? fixed_one : sqrt(fabs(state.g_load))); if (!block_stf && (state.netto_vario > mc + Smin)) { // stop to climb V_stf = Vmin; } else { const fixed head_wind (!positive(GetMC()) ? solution.head_wind : fixed_zero); const fixed stf_sink_rate (block_stf ? fixed_zero : -state.netto_vario); GlidePolarSpeedToFly gp_stf(*this, stf_sink_rate, head_wind, Vmin, Vmax); V_stf = gp_stf.solve(Vmax); } return max(Vmin, V_stf*g_scaling); }
static int stringprep_erl_control(ErlDrvData drv_data, unsigned int command, char *buf, int len, char **rbuf, int rlen) { int i, j, pos=1; unsigned char c; int bad = 0; int uc = 0, ruc; int size; int info; int prohibit = 0, tolower = 0; char *rstring; int *mc; int *str32; int str32len, str32pos = 0; int decomp_len, decomp_shift; int comp_pos, comp_starter_pos; int cclass_prev, cclass2; int ch1, ch2; int first_ral, last_ral, have_ral, have_l; size = len + 1; rstring = driver_alloc(size); rstring[0] = 0; str32len = len + 1; str32 = driver_alloc(str32len * sizeof(int)); switch (command) { case 0: prohibit = ACMask; tolower = 1; break; case NAMEPREP_COMMAND: prohibit = ACMask; tolower = 1; break; case NODEPREP_COMMAND: prohibit = ACMask | C11Mask | C21Mask | XNPMask; tolower = 1; break; case RESOURCEPREP_COMMAND: prohibit = ACMask | C21Mask; tolower = 0; break; } for (i = 0; i < len; i++) { c = buf[i]; if (c < 0x80) { uc = c; } else if (c < 0xC0) { bad = 1; } else if (c < 0xE0) { if (i+1 < len && (buf[i+1] & 0xC0) == 0x80) { uc = ((c & 0x1F) << 6) | (buf[i+1] & 0x3F); i++; } else { bad = 1; } } else if (c < 0xF0) { if (i+2 < len && (buf[i+1] & 0xC0) == 0x80 && (buf[i+2] & 0xC0) == 0x80) { uc = ((c & 0x0F) << 12) | ((buf[i+1] & 0x3F) << 6) | (buf[i+2] & 0x3F); i += 2; } else { bad = 1; } } else if (c < 0xF8) { if (i+3 < len && (buf[i+1] & 0xC0) == 0x80 && (buf[i+2] & 0xC0) == 0x80 && (buf[i+3] & 0xC0) == 0x80) { uc = ((c & 0x07) << 18) | ((buf[i+1] & 0x3F) << 12) | ((buf[i+2] & 0x3F) << 6) | (buf[i+3] & 0x3F); i += 3; if (uc > 0x10FFFF) bad = 1; } else { bad = 1; } } else { bad = 1; } if (bad) { *rbuf = rstring; driver_free(str32); return 1; } info = GetUniCharInfo(uc); if (!(info & B1Mask)) { if (tolower) { if (!(info & MCMask)) { ruc = uc + GetDelta(info); ADD_DECOMP(ruc); } else { mc = GetMC(info); for (j = 1; j <= mc[0]; j++) { ruc = mc[j]; ADD_DECOMP(ruc); } } } else { ruc = uc; ADD_DECOMP(ruc); } } } if (str32pos == 0) { rstring[0] = 1; *rbuf = rstring; driver_free(str32); return 1; } canonical_ordering(str32, str32pos); comp_pos = 1; comp_starter_pos = 0; ch1 = str32[0]; cclass_prev = GetUniCharCClass(ch1); for (i = 1; i < str32pos; i++) { ch2 = str32[i]; cclass2 = GetUniCharCClass(ch2); if ((cclass_prev == 0 || cclass2 > cclass_prev) && (ruc = compose(ch1, ch2))) { ch1 = ruc; } else { if (cclass2 == 0) { str32[comp_starter_pos] = ch1; comp_starter_pos = comp_pos++; ch1 = ch2; cclass_prev = 0; } else { str32[comp_pos++] = ch2; cclass_prev = cclass2; } } } str32[comp_starter_pos] = ch1; str32pos = comp_pos; last_ral = have_ral = have_l = 0; info = GetUniCharInfo(str32[0]); first_ral = info & D1Mask; for (i = 0; i < str32pos; i++) { ruc = str32[i]; info = GetUniCharInfo(ruc); if (info & prohibit) { *rbuf = rstring; driver_free(str32); return 1; } last_ral = info & D1Mask; have_ral = have_ral || last_ral; have_l = info & D2Mask; ADD_UCHAR(ruc); } if (have_ral && (!first_ral || !last_ral || have_l)) { *rbuf = rstring; driver_free(str32); return 1; } rstring[0] = 1; *rbuf = rstring; driver_free(str32); return pos; }