/* return array [{1=error,2=now,3=timer}, hour, minute] * */ void split_time(char* input, int result[]){ result[0] = 1; result[1] = 0; result[2] = 0; char * hour; char * minute; hour = strtok( input, ":" ); minute = strtok(NULL, ":" ); if (strcmp(hour, "now")==0){ result[0] = 2; return; } if (minute == NULL || hour == NULL || !is_integer(minute) || !is_integer(hour) || atoi(minute) < 0 || atoi(minute) > 59 || atoi(hour) < 0 || atoi(hour) > 23){ return; } result[0] = 3; result[1] = atoi(minute); result[2] = atoi(hour); }
int main(int argc, char **argv) { if (argc < 3) { usage(argv[0]); exit(EXIT_FAILURE); } int x, a[argc-2]; try { if (!is_integer(argv[1])) throw "Value must be integer!"; else x = atoi(argv[1]); for (int i=2; i<argc; i++) if (!is_integer(argv[i])) throw "Arguments must be integers!"; else a[i-2] = atoi(argv[i]); } catch (const char *e) { usage(argv[0]); std::cerr << e << std::endl; } print(a, argc-2, x); std::cout << " = "; std::cout << horner(a, argc-2, x) << std::endl; }
int main(int argc, char **argv) { try { if (argc != 3) throw "Must enter two arguments!"; if (!is_integer(argv[1])) throw "First argument must be integer!"; if (!is_integer(argv[2])) throw "Second argument must be integer!"; } catch (const char *e) { usage(argv[0]); std::cerr << e << std::endl; exit(EXIT_FAILURE); } std::cout << exp(atoi(argv[1]), atoi(argv[2])) << std::endl; }
Term SplitIndices(Term t, List *ilist) { Term rt,tt,t1=0; rt=ConsumeCompoundArg(t,1); tt=ConsumeCompoundArg(t,2); FreeAtomic(t); while(is_compound(tt)) { t1=CompoundName(tt); if(t1!=OPR_CARET && t1!=OPR_USCORE) { if(!IsTermInput()) printf("File \"%s\", line %d: ",CurrentInputFile(), CurrentInputLine()); printf("Semantic error: \'"); WriteTerm(tt); printf("\' is not appropriate index.\n"); FreeAtomic(tt); return 0; } t1=ConsumeCompoundArg(tt,1); if(!is_atom(t1) && !is_integer(t1)) { if(!IsTermInput()) printf("File \"%s\", line %d: ",CurrentInputFile(), CurrentInputLine()); printf("Semantic error: \'"); WriteTerm(t1); printf("\' is not appropriate index.\n"); FreeAtomic(tt);FreeAtomic(t1); return 0; } *ilist=AppendLast(*ilist,t1); t1=ConsumeCompoundArg(tt,2); FreeAtomic(tt); tt=t1; } if(!is_atom(tt) && !is_integer(tt)) { if(!IsTermInput()) printf("File \"%s\", line %d: ",CurrentInputFile(), CurrentInputLine()); printf("Semantic error: \'"); WriteTerm(tt); printf("\' is not appropriate index.\n"); FreeAtomic(tt); return 0; } *ilist=AppendLast(*ilist,tt); return rt; }
void kitten_isi(Boxed stack, Boxed definitions) { assert(stack); assert(is_quotation(stack)); Boxed a = pop(stack); push(stack, integer_new(is_integer(a))); boxed_free(a); }
int fastddc_init(fastddc_t* ddc, float transition_bw, int decimation, float shift_rate) { ddc->pre_decimation = 1; //this will be done in the frequency domain ddc->post_decimation = decimation; //this will be done in the time domain while( is_integer((float)ddc->post_decimation/2) && ddc->post_decimation/2 != 1) { ddc->post_decimation/=2; ddc->pre_decimation*=2; } ddc->taps_min_length = firdes_filter_len(transition_bw); //his is the minimal number of taps to achieve the given transition_bw; we are likely to have more taps than this number. ddc->taps_length = next_pow2(ceil(ddc->taps_min_length/(float)ddc->pre_decimation) * ddc->pre_decimation) + 1; //the number of taps must be a multiple of the decimation factor ddc->fft_size = next_pow2(ddc->taps_length * 4); //it is a good rule of thumb for performance (based on the article), but we should do benchmarks while (ddc->fft_size<ddc->pre_decimation) ddc->fft_size*=2; //fft_size should be a multiple of pre_decimation. ddc->overlap_length = ddc->taps_length - 1; ddc->input_size = ddc->fft_size - ddc->overlap_length; ddc->fft_inv_size = ddc->fft_size / ddc->pre_decimation; //Shift operation in the frequency domain: we can shift by a multiple of v. ddc->v = ddc->fft_size/ddc->overlap_length; //overlap factor | +-1 ? (or maybe ceil() this?) int middlebin=ddc->fft_size / 2; ddc->startbin = middlebin + middlebin * (-shift_rate) * 2; //fprintf(stderr, "ddc->startbin=%g\n",(float)ddc->startbin); ddc->startbin = ddc->v * round( ddc->startbin / (float)ddc->v ); //fprintf(stderr, "ddc->startbin=%g\n",(float)ddc->startbin); ddc->offsetbin = ddc->startbin - middlebin; ddc->post_shift = (ddc->pre_decimation)*(shift_rate+((float)ddc->offsetbin/ddc->fft_size)); ddc->pre_shift = ddc->offsetbin/(float)ddc->fft_size; ddc->dsadata = decimating_shift_addition_init(ddc->post_shift, ddc->post_decimation); //Overlap is scrapped, not added ddc->scrap=ddc->overlap_length/ddc->pre_decimation; //TODO this is problematic sometimes! overlap_length = 401 :: scrap = 200 ddc->post_input_size=ddc->fft_inv_size-ddc->scrap; return ddc->fft_size<=2; //returns true on error }
/** * Test that choice_option correctly reports its capabilities. */ TEST(choice_option_test, capabilities) { auto short_name = std::string("f"); auto name = std::string("foo"); auto option = qflags::choice_option(name.c_str(), short_name.c_str(), {"bar", "baz"}, "bar"); EXPECT_EQ(name, option.name()); EXPECT_EQ(short_name, option.short_name()); EXPECT_EQ(false, option.is_set()); EXPECT_EQ(false, option.is_flag()); EXPECT_EQ(false, option.is_command()); EXPECT_EQ(false, option.is_array()); EXPECT_EQ(false, option.is_boolean()); EXPECT_EQ(false, option.is_integer()); EXPECT_EQ(true, option.is_string()); EXPECT_EQ(0u, option.array_size()); EXPECT_THROW(option.value_boolean(), std::logic_error); EXPECT_THROW(option.value_integer(), std::logic_error); EXPECT_EQ("bar", option.value_string()); EXPECT_THROW(option.value_array(0), std::logic_error); EXPECT_THROW(static_cast<bool>(option), std::logic_error); EXPECT_THROW(static_cast<int64_t>(option), std::logic_error); EXPECT_THROW(static_cast<int>(option), std::logic_error); EXPECT_EQ("bar", static_cast<std::string>(option)); }
inline T type<T>::one() { if( is_integer() ) return std::numeric_limits<T>::max(); else return static_cast<T>(1); }
TEST(ArrayBuilder, WithAllInMultipleTimes) { cpp_redis::builders::array_builder builder; std::string buffer = "4\r\n+simple_string\r"; builder << buffer; buffer += "\n-error\r\n:42\r\n"; builder << buffer; buffer += "$5\r\nhello\r\n"; builder << buffer; EXPECT_EQ(true, builder.reply_ready()); EXPECT_EQ("", buffer); auto reply = builder.get_reply(); EXPECT_TRUE(reply.is_array()); auto array = reply.as_array(); EXPECT_EQ(4U, array.size()); auto row_1 = array[0]; EXPECT_TRUE(row_1.is_simple_string()); EXPECT_EQ("simple_string", row_1.as_string()); auto row_2 = array[1]; EXPECT_TRUE(row_2.is_error()); EXPECT_EQ("error", row_2.as_string()); auto row_3 = array[2]; EXPECT_TRUE(row_3.is_integer()); EXPECT_EQ(42, row_3.as_integer()); auto row_4 = array[3]; EXPECT_TRUE(row_4.is_bulk_string()); EXPECT_EQ("hello", row_4.as_string()); }
int main(int argc, char* argv[]) { for ( int i = 1; i < argc; ++i ) if ( strcmp( argv[i], "--help" ) == 0 ) return print_help(); for ( int i = 1; i < argc; ++i ) if ( strcmp( argv[i], "--version" ) == 0 ) return print_version(); for ( int i = 1; i < argc; ++i ) { if ( is_integer(argv[i]) ) print_properties_text(argv[i]); else { if ( *argv[i] == '-' ) { if ( strcmp(argv[i], "-i") == 0 ) { if ( i + 1 >= argc ) return fprintf(stderr, "ngossip: file not specified\n"); process_filename(argv[i + 1]); } } else { //process_property(argv[i]); } } } return 0; }
BIF_RETTYPE is_integer_1(BIF_ALIST_1) { if (is_integer(BIF_ARG_1)) { BIF_RET(am_true); } BIF_RET(am_false); }
/* Unbox an integer. */ Integer integer_unbox(Boxed reference) { assert(reference); assert(is_integer(reference)); Integer value = integer_value(reference); boxed_free(reference); return value; }
int NetGameEventValue::get_integer() const { if (is_integer()) return value_int; else throw Exception("NetGameEventValue is not an integer"); }
/* Parse array declarations of the form [s0][s1]..[sn], resulting in type * [s0] [s1] .. [sn] (base). * * Only the first dimension s0 can be unspecified, yielding an incomplete type. * Incomplete types are represented by having size of zero. */ static struct typetree *direct_declarator_array(struct typetree *base) { if (peek().token == '[') { long length = 0; consume('['); if (peek().token != ']') { struct var expr = constant_expression(); assert(expr.kind == IMMEDIATE); if (!is_integer(expr.type) || expr.imm.i < 1) { error("Array dimension must be a natural number."); exit(1); } length = expr.imm.i; } consume(']'); base = direct_declarator_array(base); if (!size_of(base)) { error("Array has incomplete element type."); exit(1); } base = type_init(T_ARRAY, base, length); } return base; }
const void* LLVMCodeGenerator::visit(ASTCast* node) { if (node->original->is_constant) { // constant expression if (node->type->type() == SLTypeTypePointer) { return llvm::ConstantExpr::getPointerCast(static_cast<llvm::Constant*>(_value(node->original)), _llvm_type(node->type)); } return llvm::ConstantExpr::getIntegerCast(static_cast<llvm::Constant*>(_value(node->original)), _llvm_type(node->type), node->original->type->is_signed()); } auto rr_type = SLType::RemoveReference(node->original->type); if (node->type->type() == SLTypeTypePointer) { return _builder.CreatePointerCast(_dereferenced_value(node->original), _llvm_type(node->type)); } if (node->type->type() == SLTypeTypeBool && rr_type->type() == SLTypeTypePointer) { return _builder.CreateIsNotNull(_dereferenced_value(node->original)); } if (node->type->type() == SLTypeTypeBool && rr_type->is_integer()) { return _builder.CreateICmpNE(_dereferenced_value(node->original), llvm::ConstantInt::get(_llvm_type(rr_type), 0)); } if (node->type->type() == SLTypeTypeBool && rr_type->is_floating_point()) { return _builder.CreateFCmpONE(_dereferenced_value(node->original), llvm::ConstantFP::get(_llvm_type(rr_type), 0.0)); } return _builder.CreateIntCast(_dereferenced_value(node->original), _llvm_type(node->type), node->original->type->is_signed()); }
void analyze_labeled_statement(ExecNode *s, int in_switch) { /* * 6.8.1 * #2 A case or default label shall appear only in a switch statement. * #3 Label names shall be unique within a function. */ switch (s->kind.stmt) { case LabelStmt: /* * 6.8.1 * #3 Label names shall be unique within a function. */ if (!install_label_name(s->attr.str)) ERROR(s, "duplicate label `%s'", s->attr.str); break; /* * 6.8.4.2 * #3 The expression of each case label shall be an integer constant expression and no two * of the case constant expressions in the same switch statement shall have the same value * after conversion. There may be at most one default label in a switch statement. * (Any enclosed switch statement may have a default label or case constant * expressions with values that duplicate case constant expressions in the enclosing * switch statement). */ case CaseStmt: { long long val; Token ty, cty; ++switch_case_counter[switch_nesting_level]; if (!in_switch) ERROR(s, "case label not within a switch statement"); if ((ty=get_type_category(&s->child[0]->type)) == TOK_ERROR) return; if (!is_integer(ty)) ERROR_R(s->child[0], "case label expression has non-integer type"); val = eval_const_expr(s->child[0], FALSE, TRUE); cty = switch_contr_expr_types[switch_nesting_level]; if (cty!=TOK_LONG_LONG && cty!=TOK_UNSIGNED_LONG_LONG) val = (int)val; s->child[0]->attr.val = val; if (!install_switch_label(val, FALSE)) ERROR(s, "duplicate case value `%ld'", s->child[0]->attr.val); } break; case DefaultStmt: if (!in_switch) ERROR_R(s, "default label not within a switch statement"); if (!install_switch_label(0, TRUE)) ERROR(s, "multiple default labels in one switch"); break; } }
int is_intpos (char *number) { if (is_integer (number) && atoi (number) > 0) return TRUE; else return FALSE; }
int is_intnonneg (char *number) { if (is_integer (number) && atoi (number) >= 0) return TRUE; else return FALSE; }
void mpq::ceil() { if (is_integer()) return; bool pos = is_pos(); mpz_tdiv_q(mpq_numref(m_val), mpq_numref(m_val), mpq_denref(m_val)); mpz_set_ui(mpq_denref(m_val), 1); if (pos) mpz_add_ui(mpq_numref(m_val), mpq_numref(m_val), 1); }
void mpq::floor() { if (is_integer()) return; bool neg = is_neg(); mpz_tdiv_q(mpq_numref(m_val), mpq_numref(m_val), mpq_denref(m_val)); mpz_set_ui(mpq_denref(m_val), 1); if (neg) mpz_sub_ui(mpq_numref(m_val), mpq_numref(m_val), 1); }
int is_intpercent (char *number) { int i; if (is_integer (number) && (i = atoi (number)) >= 0 && i <= 100) return TRUE; else return FALSE; }
/*GRAMMAR GET TYPES*/ struct expression_data_t* get_expr_expr_data(struct expression_t *expr, struct attribute_table_t* attr_hash_table, struct function_declaration_t *statement_func, int line_number) { if(expr->expr != NULL && expr->expr->type != NULL) { return expr->expr; /*we already have type*/ } else if(expr->se2 == NULL) /* if se2 is null then the expression type is the type of se1 */ { return get_simple_expr_expr_data(expr->se1, attr_hash_table, statement_func, line_number); } else { struct expression_data_t *se1_data = get_simple_expr_expr_data(expr->se1, attr_hash_table, statement_func, line_number); struct expression_data_t *se2_data = get_simple_expr_expr_data(expr->se2, attr_hash_table, statement_func, line_number); switch(expr->relop) { case RELOP_EQUAL: case RELOP_NOTEQUAL: if(strcmp(se1_data->type, se2_data->type)) { error_type_mismatch(line_number, se1_data->type, se2_data->type); } break; case RELOP_LT: case RELOP_GT: case RELOP_LE: case RELOP_GE: if( !is_integer(se1_data->type) && !is_real(se1_data->type) ) { error_datatype_is_not(line_number, se1_data->type, "real or integer"); } if( !is_integer(se2_data->type) && !is_real(se2_data->type) ) { error_datatype_is_not(line_number, se2_data->type, "real or integer"); } break; } return set_expression_data(EXPRESSION_DATA_BOOLEAN, "boolean"); } }
static int define_external_variables( YR_COMPILER* compiler) { for (int i = 0; ext_vars[i] != NULL; i++) { char* equal_sign = strchr(ext_vars[i], '='); if (!equal_sign) { fprintf(stderr, "error: wrong syntax for `-d` option.\n"); return FALSE; } // Replace the equal sign with null character to split the external // variable definition (i.e: myvar=somevalue) in two strings: identifier // and value. *equal_sign = '\0'; char* identifier = ext_vars[i]; char* value = equal_sign + 1; if (is_float(value)) { yr_compiler_define_float_variable( compiler, identifier, atof(value)); } else if (is_integer(value)) { yr_compiler_define_integer_variable( compiler, identifier, atoi(value)); } else if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) { yr_compiler_define_boolean_variable( compiler, identifier, strcmp(value, "true") == 0); } else { yr_compiler_define_string_variable( compiler, identifier, value); } } return TRUE; }
std::set<T> factors(T Num){ if(!is_integer(Num)) throw pulsar::PulsarException("Integer required"); std::set<T> f; T max=(T)floor(sqrt(numeric_cast<double>(Num))); for(T i=1;i<=max;++i) if(Num%i==0){ f.insert(i); f.insert(Num/i); } return f; }
int main() { char string[] = "123"; int number; if (is_integer(string)){ number = atoi(string); printf("Your number is: %i\n", number); } return 0; }
void kitten_putc(Boxed stack, Boxed definitions) { trace("kitten_putc()\n"); assert(stack); assert(is_quotation(stack)); assert(is_integer(top(stack))); Boxed a = pop(stack); Integer character = integer_unbox(a); assert(character >= 0 && character <= UINT32_MAX); char buffer[5] = { 0 }; utf8_append(character, (uint8_t*)buffer); printf("%s", buffer); }
TEST(IntegerBuilder, WithAllInOneTime) { cpp_redis::builders::integer_builder builder; std::string buffer = "42\r\n"; builder << buffer; EXPECT_EQ(true, builder.reply_ready()); EXPECT_EQ("", buffer); auto reply = builder.get_reply(); EXPECT_TRUE(reply.is_integer()); EXPECT_EQ(42, reply.as_integer()); }
TEST(IntegerBuilder, NegativeNumber) { cpp_redis::builders::integer_builder builder; std::string buffer = "-1\r\n"; builder << buffer; EXPECT_EQ(true, builder.reply_ready()); EXPECT_EQ("", buffer); auto reply = builder.get_reply(); EXPECT_TRUE(reply.is_integer()); EXPECT_EQ(-1, reply.as_integer()); }
void kitten_write(Boxed stack, Boxed definitions) { assert(stack); assert(is_quotation(stack)); if (is_integer(top(stack))) { Boxed a = pop(stack); Integer value = integer_unbox(a); printf("%ld", value); } else if (is_float(top(stack))) { Boxed a = pop(stack); Float value = float_unbox(a); printf("%f", value); } }
int main (int argc, char **argv) { int result = STATE_UNKNOWN; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); if (argc < 2) usage4 (_("Could not parse arguments")); else if (strcmp (argv[1], "-V") == 0 || strcmp (argv[1], "--version") == 0) { print_revision (progname, NP_VERSION); exit (STATE_OK); } else if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0) { print_help (); exit (STATE_OK); } else if (!is_integer (argv[1])) usage4 (_("Arguments to check_dummy must be an integer")); else result = atoi (argv[1]); switch (result) { case STATE_OK: printf (_("OK")); break; case STATE_WARNING: printf (_("WARNING")); break; case STATE_CRITICAL: printf (_("CRITICAL")); break; case STATE_UNKNOWN: printf (_("UNKNOWN")); break; default: printf (_("UNKNOWN")); printf (": "); printf (_("Status %d is not a supported error state\n"), result); return STATE_UNKNOWN; } if (argc >= 3) printf (": %s", argv[2]); printf("\n"); return result; }