int verifyNumberString(char *eingabe) { int slashes=0; int nonnumerics=0; int i = 0; int slashposition=0; int length=0; for (i = 0;eingabe[i]; ++i) //analysiere Eingabe nach Slashes, die von Ziffern umgeben sind { length=i; if (eingabe[i]=='/' && numeric(eingabe[i+1]) && numeric(eingabe[i-1])) { slashes++; slashposition=i; } if(!numeric(eingabe[i]))// und zaehle Zeichen, die nicht Ziffern sind. nonnumerics++; } if(slashes==1 && nonnumerics==1 && eingabe[0]=='0' && slashposition==5 && length==11)// Eingabe hat korrektes Format { return(0); } else { // neu einlesen printf( "Die Eingabe war nicht korrekt!\nBitte geben Sie eine Telefonnummer im Format \"Vorwahl/Nummer\" ein.\n"); scanf("%s", eingabe); verifyNumberString(eingabe); } return(0); }
static int expr_mult(State_t* state, Node_t *np) { register int tok = expr_cond(state, np); while ((tok&~T_OP)==T_MULT) { Node_t rp; int op = (tok&T_OP); tok = expr_cond(state, &rp); if (!numeric(np) || !numeric(&rp)) error(ERROR_exit(2),"non-numeric argument"); if (op && rp.num==0) error(ERROR_exit(2),"division by zero"); switch(op) { case 0: np->num *= rp.num; break; case 1: np->num /= rp.num; break; case 2: np->num %= rp.num; } np->type = T_NUM; } return tok; }
static ex asin_eval(const ex & x) { if (x.info(info_flags::numeric)) { // asin(0) -> 0 if (x.is_zero()) return x; // asin(1/2) -> Pi/6 if (x.is_equal(_ex1_2)) return numeric(1,6)*Pi; // asin(1) -> Pi/2 if (x.is_equal(_ex1)) return _ex1_2*Pi; // asin(-1/2) -> -Pi/6 if (x.is_equal(_ex_1_2)) return numeric(-1,6)*Pi; // asin(-1) -> -Pi/2 if (x.is_equal(_ex_1)) return _ex_1_2*Pi; // asin(float) -> float if (!x.info(info_flags::crational)) return asin(ex_to<numeric>(x)); // asin() is odd if (x.info(info_flags::negative)) return -asin(-x); } return asin(x).hold(); }
void read_interval_spec(char *spec, intervalmgr_t *im) { long a, b; bool_t badrange = FALSE; char *p, *q; p = strtok(spec, ","); while( p && !badrange ) { q = strchr(p, '-'); if( !q ) { a = b = numeric(p) ? atoi(p) : ((badrange = TRUE), 0); } else { *q++ = '\0'; a = numeric(p) ? atoi(p) : ((badrange = TRUE), 0); b = numeric(q) ? atoi(q) : ((badrange = TRUE), 0); if( a == 0 ) { a = 1; } if( b == 0 ) { b = 65535; } } if( badrange ) { errormsg(E_FATAL, "bad range. Try 1, 1-10, -10, 1-, etc.\n"); exit(EXIT_FAILURE); } else { push_intervalmgr(im, a, b); } p = strtok(NULL, ","); } }
bool Assign::check(Type *a,Type *b){ if(!numeric(a) || !numeric(b)) return false; else if(a == Type::Char && b == Type::Int) return false; else return true; }
Type* Type::max(Type *p1, Type *p2) { if( !numeric(p1) || !numeric(p2)) return nullptr; if(p1 == Type::Int || p2 == Type::Int ) return Type::Int; else return Type::Char; }
inline void promoteNumeric(Value& v1, Value& v2) { if (!numeric(v1) || !numeric(v2)) return; if (sameType(v1,v2)) return; switch (v1.type) { case Value::T_INEXACT: v2 = double(v2.i); return; case Value::T_EXACT: v1 = double(v1.i); return; default: assert(false); } }
void update(Cell c, int xIndex, int yIndex, int labelIndex) { int x, y; x = numeric(inputStrings[ (xIndex) % MAX_strings]); y = numeric(inputStrings[ (yIndex) % MAX_strings]); board[x-1][y-1] = c; if (labelIndex >= 0) { label = numeric(inputStrings[(labelIndex - 3)% MAX_strings]); boardLabels[x-1][y-1] = label; } }
/** * Compute the primitive part and the content of a modular multivariate * polynomial e \in Z_p[x_n][x_0, \ldots, x_{n-1}], i.e. e is considered * a polynomial in variables x_0, \ldots, x_{n-1} with coefficients being * modular polynomials Z_p[x_n] * @param e polynomial to operate on * @param pp primitive part of @a e, will be computed by this function * @param c content (in the sense described above) of @a e, will be * computed by this function * @param vars variables x_0, \ldots, x_{n-1}, x_n * @param p modulus */ void primpart_content(ex& pp, ex& c, ex e, const exvector& vars, const long p) { static const ex ex1(1); static const ex ex0(0); e = e.expand(); if (e.is_zero()) { pp = ex0; c = ex1; return; } exvector rest_vars = vars; rest_vars.pop_back(); ex_collect_t ec; collect_vargs(ec, e, rest_vars); if (ec.size() == 1) { // the input polynomial factorizes into // p_1(x_n) p_2(x_0, \ldots, x_{n-1}) c = ec.rbegin()->second; ec.rbegin()->second = ex1; pp = ex_collect_to_ex(ec, rest_vars).expand().smod(numeric(p)); return; } // Start from the leading coefficient (which is stored as a last // element of the terms array) auto i = ec.rbegin(); ex g = i->second; // there are at least two terms, so it's safe to... ++i; while (i != ec.rend() && !g.is_equal(ex1)) { g = euclid_gcd(i->second, g, vars.back(), p); ++i; } if (g.is_equal(ex1)) { pp = e; c = ex1; return; } exvector mainvar; mainvar.push_back(vars.back()); for (i = ec.rbegin(); i != ec.rend(); ++i) { ex tmp(0); if (!divide_in_z_p(i->second, g, tmp, mainvar, p)) throw std::logic_error(std::string(__func__) + ": bogus division failure"); i->second = tmp; } pp = ex_collect_to_ex(ec, rest_vars).expand().smod(numeric(p)); c = g; }
static ex acos_eval(const ex & x) { if (x.info(info_flags::numeric)) { // acos(1) -> 0 if (x.is_equal(_ex1)) return _ex0; // acos(1/2) -> Pi/3 if (x.is_equal(_ex1_2)) return _ex1_3*Pi; // acos(0) -> Pi/2 if (x.is_zero()) return _ex1_2*Pi; // acos(-1/2) -> 2/3*Pi if (x.is_equal(_ex_1_2)) return numeric(2,3)*Pi; // acos(-1) -> Pi if (x.is_equal(_ex_1)) return Pi; // acos(float) -> float if (!x.info(info_flags::crational)) return acos(ex_to<numeric>(x)); // acos(-x) -> Pi-acos(x) if (x.info(info_flags::negative)) return Pi-acos(-x); } return acos(x).hold(); }
TEST_F(InstanceTest, Character_construction_with_representation) { CharacterInstance numeric("'1'"); EXPECT_EQ(numeric.type(), "Character"); EXPECT_EQ(numeric.name(), ""); EXPECT_EQ(numeric.value(), '1'); EXPECT_EQ(numeric.representation(), "'1'"); }
int tci_file_header_display (tci_hdr header, char* format) { char* disp_time = NULL; printf ("File Data Rate %u MW/s\n", (u_int)header.hdr_drate); printf ("Header Size %i B\n\n", header.hdr_size); if (!numeric(header.hdr_time)) disp_time = strdup ("no time in header\n"); else { disp_time = strdup (header.hdr_time); } printf ("File Start Time %s\n", disp_time); free (disp_time); printf ("Recorder Mode %s\n", header.hdr_s2mode); printf ("Tape ID %s\n\n", header.hdr_tapeid); printf ("______________User_info______________________\n"); printf ("# LABEL INFO\n\n"); printf ("1 %-*s: %s\n", 23, header.hdr_labels[0], header.hdr_usr_field1); printf ("2 %-*s: %s\n", 23, header.hdr_labels[1], header.hdr_usr_field2); printf ("3 %-*s: %s\n", 23, header.hdr_labels[2], header.hdr_usr_field3); printf ("4 %-*s: %s\n\n",23, header.hdr_labels[3], header.hdr_usr_field4); return (0); }
char *select_image(char *image) /* Look image up on the filesystem, if it is a file then we're done, but * if its a directory then we want the newest file in that directory. If * it doesn't exist at all, then see if it is 'number:number' and get the * image from that absolute offset off the disk. */ { ino_t image_ino; struct stat st; image= strcpy(malloc((strlen(image) + 1 + NAME_MAX + 1) * sizeof(char)), image); fsok= r_super(&block_size) != 0; if (!fsok || (image_ino= r_lookup(ROOT_INO, image)) == 0) { char *size; if (numprefix(image, &size) && *size++ == ':' && numeric(size)) { vir2sec= flat_vir2sec; image_off= a2l(image); image_sectors= a2l(size); strcpy(image, "Minix"); return image; } if (!fsok) printf("No image selected\n"); else printf("Can't load %s: %s\n", image, unix_err(errno)); goto bail_out; } r_stat(image_ino, &st); image_bytes = st.st_size; if (!S_ISREG(st.st_mode)) { char *version= image + strlen(image); char dots[NAME_MAX + 1]; if (!S_ISDIR(st.st_mode)) { printf("%s: %s\n", image, unix_err(ENOTDIR)); goto bail_out; } (void) r_readdir(dots); (void) r_readdir(dots); /* "." & ".." */ *version++= '/'; *version= 0; if ((image_ino= latest_version(version, &st)) == 0) { printf("There are no images in %s\n", image); goto bail_out; } r_stat(image_ino, &st); } vir2sec= file_vir2sec; image_sectors= (st.st_size + SECTOR_SIZE - 1) >> SECTOR_SHIFT; return image; bail_out: free(image); return nil; }
ModResult ModuleSpanningTree::HandleVersion(const CommandBase::Params& parameters, User* user) { // We've already confirmed that !parameters.empty(), so this is safe TreeServer* found = Utils->FindServerMask(parameters[0]); if (found) { if (found == Utils->TreeRoot) { // Pass to default VERSION handler. return MOD_RES_PASSTHRU; } // If an oper wants to see the version then show the full version string instead of the normal, // but only if it is non-empty. // If it's empty it might be that the server is still syncing (full version hasn't arrived yet) // or the server is a 2.0 server and does not send a full version. bool showfull = ((user->IsOper()) && (!found->GetFullVersion().empty())); Numeric::Numeric numeric(RPL_VERSION); irc::tokenstream tokens(showfull ? found->GetFullVersion() : found->GetVersion()); for (std::string token; tokens.GetTrailing(token); ) numeric.push(token); user->WriteNumeric(numeric); } else { user->WriteNumeric(ERR_NOSUCHSERVER, parameters[0], "No such server"); } return MOD_RES_DENY; }
static ex acosh_eval(const ex & x) { if (x.info(info_flags::numeric)) { // acosh(0) -> Pi*I/2 if (x.is_zero()) return Pi*I*numeric(1,2); // acosh(1) -> 0 if (x.is_equal(_ex1)) return _ex0; // acosh(-1) -> Pi*I if (x.is_equal(_ex_1)) return Pi*I; // acosh(float) -> float if (!x.info(info_flags::crational)) return acosh(ex_to<numeric>(x)); // acosh(-x) -> Pi*I-acosh(x) if (x.info(info_flags::negative)) return Pi*I-acosh(-x); } return acosh(x).hold(); }
TEST_F(InstanceTest, Character_construction_with_message_2) { CharacterInstance numeric("createIfNotExists:withValue:", std::vector<std::string>({"numeric", "'1'"})); EXPECT_EQ(numeric.type(), "Character"); EXPECT_EQ(numeric.name(), "numeric"); EXPECT_EQ(numeric.value(), '1'); EXPECT_EQ(numeric.representation(), "'1'"); }
static ex Order_series(const ex & x, const relational & r, int order, unsigned options) { // Just wrap the function into a pseries object GINAC_ASSERT(is_a<symbol>(r.lhs())); const symbol &s = ex_to<symbol>(r.lhs()); epvector new_seq { expair(Order(_ex1), numeric(std::min(x.ldegree(s), order))) }; return pseries(r, std::move(new_seq)); }
bool is_instance(Value const& value) const { // A Scalar is a Numeric, String, Boolean, and Regexp return numeric().is_instance(value) || string().is_instance(value) || boolean().is_instance(value) || regexp().is_instance(value); }
static int expr_add(State_t* state, Node_t *np) { register int tok = expr_mult(state, np); while ((tok&~T_OP)==T_ADD) { Node_t rp; int op = (tok&T_OP); tok = expr_mult(state, &rp); if (!numeric(np) || !numeric(&rp)) error(ERROR_exit(2),"non-numeric argument"); if (op) np->num -= rp.num; else np->num += rp.num; np->type = T_NUM; } return tok; }
main() { ch = getchar(); for (j=0; ;j++) { getNextToken(); if (0 == tokenLen) break; strcpy(inputStrings[j % MAX_strings],str); printf("%s\n",inputStrings[j % MAX_strings]); if (0 == strcmp(str,"DimX")) { getNextToken(); dimX = numeric(str); } else if (0 == strcmp(str,"DimY")) { getNextToken(); dimY = numeric(str); for (x = 0; x < dimX; x++) for (y = 0; y < dimY; y++) { board[x][y] = EMPTY; boardLabels[x][y] = -1; } } else if (0 == strcmp(str,"HexBlackLabelledPiece")) update(BLACK, j-6, j-5, j); else if (0 == strcmp(str,"HexWhiteLabelledPiece")) update(WHITE, j-6, j-5, j); else if (0 == strcmp(str,"HexBlackPiece")) update(BLACK, j-2, j-1, -1); else if (0 == strcmp(str,"HexWhitePiece")) update(WHITE, j-2, j-1, -1); else if (0 == strcmp(str,"HexBlackMarkedPiece")) update(BLACKMARKED, j-2, j-1, -1); else if (0 == strcmp(str,"HexWhiteMarkedPiece")) update(WHITEMARKED, j-2, j-1, -1); else if (0 == strcmp(str,"HexDeadCell")) update(EMPTYMARKED, j-2, j-1, -1); } showBoard(dimX,dimY); showBoardLabels(dimX,dimY); }
NumericPairBase* promoteNumeric(const Value& v1, const Value& v2) { if (!numeric(v1) || !numeric(v2)) return 0; if (v1.type != v2.type) { switch (v1.type) { case Value::T_INEXACT: return new NumericPair<double>(v1.x, v2.i); case Value::T_EXACT: return new NumericPair<double>(v1.i, v2.x); default: assert(false); } } else { switch (v1.type) { case Value::T_INEXACT: return new NumericPair<double>(v1.x, v2.x); case Value::T_EXACT: return new NumericPair<int64_t>(v1.i, v2.i); default: assert(false); } } }
bool is_specialization(Type const& other) const { // Numeric, String, Boolean and Regexp are specializations // Also specializations of Numeric and String return boost::get<numeric>(&other) || boost::get<string>(&other) || boost::get<boolean>(&other) || boost::get<regexp>(&other) || numeric().is_specialization(other) || string().is_specialization(other); }
/* * d i s p W i d t h * * return display width for given column */ static int dispWidth(KSqlCursor *csr, int index) { int width = csr->selectColumnSize(index); if (numeric(csr,index)) { width++; // sign if (csr->selectColumnScale(index)) width++; // decimal point if (numwidth && width>numwidth) width = numwidth; } else if (charwidth && width>charwidth) width = charwidth; return width; } // dispWidth
static int expr_or(State_t* state, Node_t *np) { register int tok = expr_and(state, np); while (tok=='|') { Node_t rp; tok = expr_and(state, &rp); if ((numeric(np) && np->num==0) || *np->str==0) *np = rp; } return tok; }
int number(int val[]) { int k, minus, base; char c; k = minus = 1; while (k) { k = 0; if (match("+")) k = 1; if (match("-")) { minus = (-minus); k = 1; } } if (!numeric(c = ch ())) return (0); if (match("0x") || match ("0X")) while (numeric(c = ch ()) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { inbyte (); k = k * 16 + (numeric (c) ? (c - '0') : ((c & 07) + 9)); } else { base = (c == '0') ? 8 : 10; while (numeric(ch())) { c = inbyte (); k = k * base + (c - '0'); } } if (minus < 0) k = (-k); val[0] = k; if(k < 0) { return (UINT); } else { return (CINT); } }
static int convarg(char *ap) { short ids[2]; if (!ap) return (-2); if (numeric(*ap)) return (atoi(ap)); if (strcmp(ap, "all") == 0) return (-1); errflg = 1; return (-2); }
CmdResult CommandVersion::Handle(User* user, const Params& parameters) { Numeric::Numeric numeric(RPL_VERSION); irc::tokenstream tokens(ServerInstance->GetVersionString(user->IsOper())); for (std::string token; tokens.GetTrailing(token); ) numeric.push(token); user->WriteNumeric(numeric); LocalUser *lu = IS_LOCAL(user); if (lu != NULL) { ServerInstance->ISupport.SendTo(lu); } return CMD_SUCCESS; }
static int expr_and(State_t* state, Node_t *np) { register int tok = expr_cmp(state, np); while (tok=='&') { Node_t rp; tok = expr_cmp(state, &rp); if ((numeric(&rp) && rp.num==0) || *rp.str==0) { np->num = 0; np->type=T_NUM; } } return tok; }
static Value eatNumeric(std::istream& stream, char firstChar) { std::string numeric(1, firstChar); while (!stream.eof()) { char token = stream.peek(); if ((token >= '0' && token <= '9') || token == '.' || token == '-' || token == 'E') numeric += stream.get(); else break; } if (numeric.find('.') == std::string::npos) return Value(atoi(numeric.c_str())); else return Value((float)atof(numeric.c_str())); };
int convert(nialptr * x, int *kx, int k) { if (numeric(k)) { nialptr z = Null; int v = valence(*x); nialint i, t = tally(*x); switch (k) { case inttype: /* must be converting a booltype array */ { nialint *zptr; z = new_create_array(inttype, v, 0, shpptr(*x, v)); zptr = pfirstint(z); /* safe */ for (i = 0; i < t; i++) *zptr++ = fetch_bool(*x, i); } break; case realtype: /* converting a boolean or integer array */ { double *zptr; z = new_create_array(realtype, v, 0, shpptr(*x, v)); zptr = pfirstreal(z); /* safe */ if (*kx == booltype) { for (i = 0; i < t; i++) *zptr++ = (double) fetch_bool(*x, i); } else { nialint *xptr = pfirstint(*x); /* safe */ for (i = 0; i < t; i++) *zptr++ = (double) *xptr++; } } break; } freeup(*x); *x = z; *kx = kind(z); return true; } return false; }