LISP_OBJ_PTR mult(LISP_OBJ_PTR args) { LISP_OBJ_PTR res = alloc_obj(); int int_res = 1; float float_res = 1; BOOLEAN is_float = FALSE; while (args != nil_ptr) { // check to see if we should be adding floats if (is_float(car(args)) && !is_float) { float_res = int_res; is_float = TRUE; } // grab the proper number if (is_float(car(args))) { float_res *= float_value(car(args)); } else if (!is_float) int_res *= int_value(car(args)); else float_res *= int_value(car(args)); args = cdr(args); } if (is_float) { form(res) = FLOAT_FORM; float_value(res) = float_res; } else { form(res) = INT_FORM; int_value(res) = int_res; } return res; }
LISP_OBJ_PTR eq(LISP_OBJ_PTR args) { LISP_OBJ_PTR current = car(args); LISP_OBJ_PTR to_test; BOOLEAN res = TRUE; args = cdr(args); while (args != nil_ptr) { to_test = car(args); if (is_int(current) && is_int(to_test)) res = (int_value(current) == int_value(to_test)); else if (is_int(current) && is_float(to_test)) res = (int_value(current) == float_value(to_test)); else if (is_float(current) && is_int(to_test)) res = (float_value(current) == int_value(to_test)); else res = (float_value(current) == float_value(to_test)); if (!res) { return false_ptr; } current = to_test; args = cdr(args); } return true_ptr; }
LISP_OBJ_PTR divide(LISP_OBJ_PTR args) { LISP_OBJ_PTR res = alloc_obj(); float float_res = 0; // for now, this always coerces to a float form(res) = FLOAT_FORM; if (is_float(car(args))) { float_res = float_value(car(args)); } else float_res = int_value(car(args)); args = cdr(args); if (args == nil_ptr) { float_value(res) = 1 / float_res; return res; } // TODO: check for zero division while (args != nil_ptr) { if (is_float(car(args))) float_res /= float_value(car(args)); else float_res /= int_value(car(args)); args = cdr(args); } float_value(res) = float_res; return res; }
/** * Determines if a type is comaptible with another, for purposes of converting data. It prevents * conversions that lose information. * @param dest The data type being converted to * @param src The data type being converted from * @return True if the 'src' type can be converted to 'dest' type. */ inline bool is_compatible( data_types::enum_t dest, data_types::enum_t src ){ //We allow free conversion between floating point types if( is_float( src ) ) return is_float( dest ); //Only allow integer conversions that can't lose data. if( is_signed(src) ) return is_signed(dest) && data_types::sizes[dest] >= data_types::sizes[src]; //We allow a unsigned -> signed conversion if the bit depth increases. return is_signed(dest) ? data_types::sizes[dest] > data_types::sizes[src] : data_types::sizes[dest] >= data_types::sizes[src]; }
bool is_valid_term(const char* code_line) { unsigned long find_index=0; unsigned long find_length=strlen(code_line); char find_char='\0'; char term_left[VARIABLES_NAME_LENGTH]={0}; char term_right[VARIABLES_NAME_LENGTH]={0}; for (;find_index<find_length;++find_index) { find_char=*(char*)(code_line+find_index); if (('+'==find_char) || ('-'==find_char) || ('*'==find_char) || ('/'==find_char) || ('='==find_char) || ('<'==find_char) || ('>'==find_char)) { memcpy(term_left,code_line,find_index); memcpy(term_right,code_line+find_index+1,find_length-find_index-1); if (is_valid_variables_name(term_left)) { if (is_valid_variables_name(term_right)) { return true; } else if (is_number(term_right)) { return true; } else if (is_float(term_right)) { return true; } else if (is_char(term_right)) { return true; } else if (is_string(term_right)) { return true; } } } if (('<'==find_char && '='==*(char*)(code_line+find_index+1)) || ('>'==find_char && '='==*(char*)(code_line+find_index+1) || ('<'==find_char && '>'==*(char*)(code_line+find_index+1)))) { memset(term_left,0,VARIABLES_NAME_LENGTH); memset(term_right,0,VARIABLES_NAME_LENGTH); memcpy(term_left,code_line,find_index); memcpy(term_right,code_line+find_index+2,find_length-find_index-2); if (is_valid_variables_name(term_left)) { if (is_valid_variables_name(term_right)) { return true; } else if (is_number(term_right)) { return true; } else if (is_float(term_right)) { return true; } else if (is_char(term_right)) { return true; } else if (is_string(term_right)) { return true; } } return false; } } return false; }
static Lisp_Object Ldecode_float(Lisp_Object nil, Lisp_Object a) { double d = float_of_number(a), neg = 1.0; int x; Lisp_Object sign; if (!is_float(a)) return aerror("decode-float"); if (d < 0.0) d = -d, neg = -1.0; if (d == 0.0) x = 0; else { d = frexp(d, &x); if (d == 1.0) d = 0.5, x++; } #ifdef COMMON if (is_sfloat(a)) sign = make_sfloat(neg); else #endif sign = make_boxfloat(neg, type_of_header(flthdr(a))); errexit(); push(sign); #ifdef COMMON if (is_sfloat(a)) a = make_sfloat(d); else #endif a = make_boxfloat(d, type_of_header(flthdr(a))); pop(sign); errexit(); #ifdef COMMON mv_2 = fixnum_of_int(x); mv_3 = sign; return nvalues(a, 3); #else return list3(sign, fixnum_of_int(x), a); #endif }
int main(int argc, char** argv){ //contains decimal point if(is_float(argv[1])){ char* end; errno = 0; double d = strtod(argv[1], &end); if(errno != 0 || *end != 0){ fprintf(stderr, "invalid floating point number %s\n", argv[1]); return -1; } fp_struct fps = dissect_double(d); print_fps(stdout, fps); } else { //no decimal point, treat as a long char* end; errno = 0; long l = strtol(argv[1], &end, 10); if(errno != 0 || *end != 0){ fprintf(stderr, "invalid long integer %s\n", argv[1]); return -1; } long_struct ls = dissect_long(l); print_ls(stdout, ls); } return 0; }
BIF_RETTYPE is_float_1(BIF_ALIST_1) { if (is_float(BIF_ARG_1)) { BIF_RET(am_true); } BIF_RET(am_false); }
void kitten_isf(Boxed stack, Boxed definitions) { assert(stack); assert(is_quotation(stack)); Boxed a = pop(stack); push(stack, integer_new(is_float(a))); boxed_free(a); }
/* calculate approximate length of a printed term. For space alloc. */ DWORD clenpterm(prolog_term term) { int i, clen; if (is_var(term)) return 11; else if (is_int(term)) return 12; else if (is_float(term)) return 12; else if (is_nil(term)) return 2; else if (is_string(term)) return strlen(p2c_string(term))+5; else if (is_list(term)) { clen = 1; clen += clenpterm(p2p_car(term)) + 1; while (is_list(term)) { clen += clenpterm(p2p_car(term)) + 1; term = p2p_cdr(term); } if (!is_nil(term)) { clen += clenpterm(term) + 1; } return clen+1; } else if (is_functor(term)) { clen = strlen(p2c_functor(term))+5; if (p2c_arity(term) > 0) { clen += clenpterm(p2p_arg(term,1)) + 1; for (i = 2; i <= p2c_arity(term); i++) { clen += clenpterm(p2p_arg(term,i)) + 1; } return clen + 1; } else return clen; } else { fprintf(stderr,"error, unrecognized type"); return 0; } }
bool fpa_util::contains_floats(ast * a) { switch (a->get_kind()) { case AST_APP: { app * aa = to_app(a); if (contains_floats(aa->get_decl())) return true; else for (unsigned i = 0; i < aa->get_num_args(); i++) if (contains_floats(aa->get_arg(i))) return true; break; } case AST_VAR: return contains_floats(to_var(a)->get_sort()); break; case AST_QUANTIFIER: { quantifier * q = to_quantifier(a); for (unsigned i = 0; i < q->get_num_children(); i++) if (contains_floats(q->get_child(i))) return true; for (unsigned i = 0; i < q->get_num_decls(); i++) if (contains_floats(q->get_decl_sort(i))) return true; if (contains_floats(q->get_expr())) return true; break; } case AST_SORT: { sort * s = to_sort(a); if (is_float(s) || is_rm(s)) return true; else { for (unsigned i = 0; i < s->get_num_parameters(); i++) { parameter const & pi = s->get_parameter(i); if (pi.is_ast() && contains_floats(pi.get_ast())) return true; } } break; } case AST_FUNC_DECL: { func_decl * f = to_func_decl(a); for (unsigned i = 0; i < f->get_arity(); i++) if (contains_floats(f->get_domain(i))) return true; if (contains_floats(f->get_range())) return true; for (unsigned i = 0; i < f->get_num_parameters(); i++) { parameter const & pi = f->get_parameter(i); if (pi.is_ast() && contains_floats(pi.get_ast())) return true; } break; } default: UNREACHABLE(); } return false; }
/* Unbox a float. */ Float float_unbox(Boxed reference) { assert(reference); assert(is_float(reference)); Float value = float_value(reference); boxed_free(reference); return value; }
void test_expression_evaluator_each(GLEPolish* polish, const std::string& expression, const std::string& expectedValue) { int cp = 0; int rtype = 0; GLEPcodeList pc_list; GLEPcode pcode(&pc_list); polish->polish(expression.c_str(), pcode, &rtype); GLERC<GLEArrayImpl> stk(new GLEArrayImpl()); std::ostringstream msg; msg << expression << ": "; if (is_float(expectedValue)) { GLEMemoryCell* mc = evalGeneric(stk.get(), &pc_list, (int*)&pcode[0], &cp); gle_memory_cell_check(mc, GLEObjectTypeDouble); double expectedDouble = tokenizer_string_to_double(expectedValue.c_str()); msg << mc->Entry.DoubleVal << " == " << expectedValue; if (expectedDouble == 0.0) { unit_test_msg(fabs(mc->Entry.DoubleVal) < CUTILS_REL_PREC_FINE, msg.str()); } else { unit_test_msg(equals_rel_fine(mc->Entry.DoubleVal, expectedDouble), msg.str()); } } else { GLERC<GLEString> result(evalString(stk.get(), &pc_list, (int*)&pcode[0], &cp, true)); std::string computedString(result->toUTF8()); msg << computedString << " == " << expectedValue; unit_test_msg(expectedValue == computedString, msg.str()); } }
BIF_RETTYPE float_1(BIF_ALIST_1) { Eterm res; Eterm* hp; FloatDef f; /* check args */ if (is_not_integer(BIF_ARG_1)) { if (is_float(BIF_ARG_1)) { BIF_RET(BIF_ARG_1); } else { badarg: BIF_ERROR(BIF_P, BADARG); } } if (is_small(BIF_ARG_1)) { Sint i = signed_val(BIF_ARG_1); f.fd = i; /* use "C"'s auto casting */ } else if (big_to_double(BIF_ARG_1, &f.fd) < 0) { goto badarg; } hp = HAlloc(BIF_P, FLOAT_SIZE_OBJECT); res = make_float(hp); PUT_DOUBLE(f, hp); BIF_RET(res); }
static Eterm math_call_1(Process* p, double (*func)(double), Eterm arg1) { FloatDef a1; Eterm res; Eterm* hp; ERTS_FP_CHECK_INIT(p); if (is_float(arg1)) { GET_DOUBLE(arg1, a1); } else if (is_small(arg1)) { a1.fd = signed_val(arg1); } else if (is_big(arg1)) { if (big_to_double(arg1, &a1.fd) < 0) { badarith: p->freason = BADARITH; return THE_NON_VALUE; } } else { p->freason = BADARG; return THE_NON_VALUE; } a1.fd = (*func)(a1.fd); ERTS_FP_ERROR_THOROUGH(p, a1.fd, goto badarith); hp = HAlloc(p, FLOAT_SIZE_OBJECT); res = make_float(hp); PUT_DOUBLE(a1, hp); return res; }
void Term__tweak(caStack* stack) { Term* t = as_term_ref(circa_input(stack, 0)); if (t == NULL) return circa_output_error(stack, "NULL reference"); int steps = tweak_round(to_float(circa_input(stack, 1))); caValue* val = term_value(t); if (steps == 0) return; if (is_float(val)) { float step = get_step(t); // Do the math like this so that rounding errors are not accumulated float new_value = (tweak_round(as_float(val) / step) + steps) * step; set_float(val, new_value); } else if (is_int(val)) set_int(val, as_int(val) + steps); else circa_output_error(stack, "Ref is not an int or number"); }
bool equals(Type* type, caValue* a, caValue* b) { if (is_float(b)) return number_t::equals(type, a, b); if (!is_int(b)) return false; return as_int(a) == as_int(b); }
static Lisp_Object Linteger_decode_float(Lisp_Object nil, Lisp_Object a) { double d = float_of_number(a); #ifdef COMMON int tag = (int)a & TAG_BITS; #endif int x, neg = 0; int32_t a1, a2; CSL_IGNORE(nil); if (!is_float(a)) return aerror("integer-decode-float"); if (d == 0.0) #ifdef COMMON { mv_2 = fixnum_of_int(0); mv_3 = fixnum_of_int(d<0 ? -1 : 1); nvalues(fixnum_of_int(0), 3); } #else return list3(fixnum_of_int(0), fixnum_of_int(0), fixnum_of_int(d<0 ? -1 : 1)); #endif if (d < 0.0) d = -d, neg = 1; d = frexp(d, &x); if (d == 1.0) d = 0.5, x++; #ifdef COMMON if (tag == TAG_SFLOAT) { d *= TWO_20; x -= 20; a1 = (int32_t)d; a = fixnum_of_int(a1); } else if (tag == TAG_BOXFLOAT && type_of_header(flthdr(a)) == TYPE_SINGLE_FLOAT) { d *= TWO_24; x -= 24; a1 = (int32_t)d; a = fixnum_of_int(a1); } else #endif { d *= TWO_22; a1 = (int32_t)d; d -= (double)a1; a2 = (int32_t)(d*TWO_31); /* This conversion should be exact */ x -= 53; a = make_two_word_bignum(a1, a2); errexit(); } #ifdef COMMON { mv_2 = fixnum_of_int(x); mv_3 = neg ? fixnum_of_int(-1) : fixnum_of_int(1); return nvalues(a, 3); } #else return list3(a, fixnum_of_int(x), neg ? fixnum_of_int(-1) : fixnum_of_int(1)); #endif }
calcu_type is_valid_calculate(const char* in_code_line) { unsigned long find_flag_index=0; unsigned long string_length=strlen(in_code_line); char calculate_left[VARIABLES_NAME_LENGTH]={0}; char calculate_right[VARIABLES_NAME_LENGTH]={0}; calcu_type return_result=calcu_err; for (;find_flag_index<string_length-1;++find_flag_index) { if ('+'==*(char*)(in_code_line+find_flag_index)) return_result=calcu_add; else if ('-'==*(char*)(in_code_line+find_flag_index)) return_result=calcu_dec; else if ('*'==*(char*)(in_code_line+find_flag_index)) return_result=calcu_mul; else if ('/'==*(char*)(in_code_line+find_flag_index)) return_result=calcu_div; if (return_result) { memcpy(calculate_left,in_code_line,find_flag_index-1); memcpy(calculate_right,(const void*)(in_code_line+find_flag_index+1),string_length-find_flag_index-1); if (is_valid_variables_name(calculate_left)) { if (is_valid_variables_name(calculate_right)) return return_result; else if (is_number(calculate_right)) return return_result; else if (is_float(calculate_right)) return return_result; else if (is_char(calculate_right)) return return_result; else if (is_string(calculate_right)) return return_result; return calcu_err; } else if (is_number(calculate_left) && is_number(calculate_right)) return return_result; else if (is_float(calculate_left) && is_float(calculate_right)) return return_result; else if (is_char(calculate_left) && is_char(calculate_right) && (calcu_add==return_result || calcu_dec==return_result)) return return_result; else if (is_string(calculate_left) && is_string(calculate_right) && calcu_add==return_result) return return_result; return calcu_err; } } return calcu_err; }
KeyAxisEventHandler* KeyAxisEventHandler::from_string(UInput& uinput, int slot, bool extra_devices, const std::string& str) { typedef boost::tokenizer<boost::char_separator<char> > tokenizer; tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens)); UIEventSequence up_codes; UIEventSequence down_codes; float threshold = 0.25f; int j = 0; for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j) { switch(j) { case 0: { up_codes = UIEventSequence::from_string(*i); } break; case 1: { if (is_float(*i)) { // bit of hackery to handle simplified syntax for trigger button that don't need up/down events threshold = boost::lexical_cast<float>(*i); down_codes = up_codes; up_codes.clear(); } else { down_codes = UIEventSequence::from_string(*i); } } break; case 2: threshold = boost::lexical_cast<float>(*i); break; default: throw std::runtime_error("AxisEvent::key_from_string(): to many arguments: " + str); } } if (j == 0) { throw std::runtime_error("AxisEvent::key_from_string(): at least one argument required: " + str); } return new KeyAxisEventHandler(uinput, slot, extra_devices, up_codes, down_codes, threshold); }
Word Generator::deal_cmp(string op, Word& a, Word& b) { if (!is_float(a) && !is_float(b)) { section_text << "cmp\t" << (a.xtype == 1 ? "$" : "") << a.x << ",\t" << (b.xtype == 1 ? "$" : "") << b.x << "\n"; else_flag = get_new_label(); string jmp; if (op == "<") jmp = "jge"; else if (op == ">") jmp = "jle"; else if (op == "<=") jmp = "jg"; else if (op == ">=") jmp = "jl"; else if (op == "==") jmp = "jne"; else if (op == "!=") jmp = "je"; section_text << jmp << "\t" << else_flag << "\n"; } else { } return Word("", "", -1); }
int to_int(caValue* value) { if (is_int(value)) return as_int(value); else if (is_float(value)) return (int) as_float(value); internal_error("In to_float, type is not an int or float"); return 0; }
/* print a prolog_term into a buffer. (Atoms are quoted if !toplevel and it's necessary for Prolog reading) */ void printpterm(prolog_term term, int toplevel, char *straddr, long int *ind) { int i; if (is_var(term)) { sprintf(tempstring,"_%p",term); strcpy(straddr+*ind,tempstring); *ind += strlen(tempstring); } else if (is_int(term)) { sprintf(tempstring,"%d",p2c_int(term)); strcpy(straddr+*ind,tempstring); *ind += strlen(tempstring); } else if (is_float(term)) { sprintf(tempstring,"%f",p2c_float(term)); strcpy(straddr+*ind,tempstring); *ind += strlen(tempstring); } else if (is_nil(term)) { strcpy(straddr+*ind,"[]"); *ind += 2; } else if (is_string(term)) { printpstring(p2c_string(term),toplevel,straddr,ind); } else if (is_list(term)) { strcpy(straddr+*ind,"["); *ind += 1; printpterm(p2p_car(term),FALSE,straddr,ind); term = p2p_cdr(term); while (is_list(term)) { strcpy(straddr+*ind,","); *ind += 1; printpterm(p2p_car(term),FALSE,straddr,ind); term = p2p_cdr(term); } if (!is_nil(term)) { strcpy(straddr+*ind,"|"); *ind += 1; printpterm(term,FALSE,straddr,ind); } strcpy(straddr+*ind,"]"); *ind += 1; } else if (is_functor(term)) { printpstring(p2c_functor(term),FALSE,straddr,ind); if (p2c_arity(term) > 0) { strcpy(straddr+*ind,"("); *ind += 1; printpterm(p2p_arg(term,1),FALSE,straddr,ind); for (i = 2; i <= p2c_arity(term); i++) { strcpy(straddr+*ind,","); *ind += 1; printpterm(p2p_arg(term,i),FALSE,straddr,ind); } strcpy(straddr+*ind,")"); *ind += 1; } } else fprintf(stderr,"error, unrecognized type"); }
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; }
exprt interval_domaint::make_expression(const symbol_exprt &src) const { if(is_int(src.type())) { int_mapt::const_iterator i_it=int_map.find(src.get_identifier()); if(i_it==int_map.end()) return true_exprt(); const integer_intervalt &interval=i_it->second; if(interval.is_top()) return true_exprt(); if(interval.is_bottom()) return false_exprt(); exprt::operandst conjuncts; if(interval.upper_set) { exprt tmp=from_integer(interval.upper, src.type()); conjuncts.push_back(binary_relation_exprt(src, ID_le, tmp)); } if(interval.lower_set) { exprt tmp=from_integer(interval.lower, src.type()); conjuncts.push_back(binary_relation_exprt(tmp, ID_le, src)); } return conjunction(conjuncts); } else if(is_float(src.type())) { float_mapt::const_iterator i_it=float_map.find(src.get_identifier()); if(i_it==float_map.end()) return true_exprt(); const ieee_float_intervalt &interval=i_it->second; if(interval.is_top()) return true_exprt(); if(interval.is_bottom()) return false_exprt(); exprt::operandst conjuncts; if(interval.upper_set) { exprt tmp=interval.upper.to_expr(); conjuncts.push_back(binary_relation_exprt(src, ID_le, tmp)); } if(interval.lower_set) { exprt tmp=interval.lower.to_expr(); conjuncts.push_back(binary_relation_exprt(tmp, ID_le, src)); } return conjunction(conjuncts); } else return true_exprt(); }
static void builder_emit_dst_store(struct builder *bld, int avx_reg, struct inst *inst, struct inst_dst *dst) { struct inst_common common = unpack_inst_common(inst); int subnum; /* FIXME: write masks */ if (dst->hstride > 1) stub("eu: dst hstride %d is > 1", dst->hstride); if (common.saturate) { int zero = builder_get_reg_with_uniform(bld, 0); int one = builder_get_reg_with_uniform(bld, float_to_u32(1.0f)); ksim_assert(is_float(dst->file, dst->type)); builder_emit_vmaxps(bld, avx_reg, avx_reg, zero); builder_emit_vminps(bld, avx_reg, avx_reg, one); } if (common.access_mode == BRW_ALIGN_1) subnum = dst->da1_subnum; else subnum = dst->da16_subnum; uint32_t offset = offsetof(struct thread, grf[dst->num]) + subnum + bld->exec_offset * dst->hstride * type_size(dst->type); switch (bld->exec_size * type_size(dst->type)) { case 32: builder_emit_m256i_store(bld, avx_reg, offset); break; case 16: builder_emit_m128i_store(bld, avx_reg, offset); break; case 4: builder_emit_u32_store(bld, avx_reg, offset); break; default: stub("eu: type size %d in dest store", type_size(dst->type)); break; } /* FIXME: For a straight move, this makes the AVX2 register * refer to the dst region. That's fine, but the register may * still also shadow the src region, but since we only track * one region per AVX2 reg, that is lost. */ fill_region_for_dst(&bld->regs[avx_reg].region, dst, offset, bld); builder_invalidate_region(bld, &bld->regs[avx_reg].region); bld->regs[avx_reg].contents |= BUILDER_REG_CONTENTS_EU_REG; }
void write_term_value(SourceWriter* writer, Term* term) { caValue* val = term_value(term); if (is_int(val)) { writer->write(as_cstring(val)); } else if (is_float(val)) { writer->write(as_cstring(val)); } else if (is_string(val)) { writer->write("\""); writer->write(as_cstring(val)); writer->write("\""); } }
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); } }
BIF_RETTYPE abs_1(BIF_ALIST_1) { Eterm res; Sint i0, i; Eterm* hp; /* integer arguments */ if (is_small(BIF_ARG_1)) { i0 = signed_val(BIF_ARG_1); i = ERTS_SMALL_ABS(i0); if (i0 == MIN_SMALL) { hp = HAlloc(BIF_P, BIG_UINT_HEAP_SIZE); BIF_RET(uint_to_big(i, hp)); } else { BIF_RET(make_small(i)); } } else if (is_big(BIF_ARG_1)) { if (!big_sign(BIF_ARG_1)) { BIF_RET(BIF_ARG_1); } else { int sz = big_arity(BIF_ARG_1) + 1; Uint* x; hp = HAlloc(BIF_P, sz); /* See note at beginning of file */ sz--; res = make_big(hp); x = big_val(BIF_ARG_1); *hp++ = make_pos_bignum_header(sz); x++; /* skip thing */ while(sz--) *hp++ = *x++; BIF_RET(res); } } else if (is_float(BIF_ARG_1)) { FloatDef f; GET_DOUBLE(BIF_ARG_1, f); if (f.fd < 0.0) { hp = HAlloc(BIF_P, FLOAT_SIZE_OBJECT); f.fd = fabs(f.fd); res = make_float(hp); PUT_DOUBLE(f, hp); BIF_RET(res); } else BIF_RET(BIF_ARG_1); } BIF_ERROR(BIF_P, BADARG); }
// Read csv into map of vectors int read_in_file(map< string, vector<float> > *files, FILE *infile, map<string, uint> &fnames, vector< pair< uint, vector<float> > > &lines){ if(files && infile){ char *line = (char*)malloc(sizeof(char) * LINE_SIZE); char *token = NULL; // Get line size_t lineSize = LINE_SIZE; int numLines = 0; while(getline(&line, &lineSize, infile)){ // Get first token, the filename token = strtok(line, DELIMS); if(token){ // Put token into string std::string fname (token); fnames[fname] = numLines; // read in floats vector<float> floats(NUM_FLOATS); uint i = 0; do{ token = strtok(NULL, DELIMS); if(token && is_float(token)){ float temp = atof(token); floats[i]=temp; } else break; i++; }while( i <= NUM_FLOATS); // Add fname and vector to map (*files)[fname] = floats; pair <uint, vector<float> > temp(numLines, floats); lines.push_back(temp); } else{ break; } numLines ++; } free(line); return numLines; } return 0; }