/* * ESC * i <nbytes> W * * Set viewing illuminant. This command is related to the configure image * data object only in the sense that both apply to palettes. The command * is implemented in this file as it is the only other command that involves * binary floating point number arrays. * * This routine will convert the whitepoint to the form anticipated by the * gs_cie_render structure (i.e., Y = 1.0). */ static int set_view_illuminant(pcl_args_t * pargs, pcl_state_t * pcs) { uint len = uint_arg(pargs); const byte *pbuff = arg_data(pargs); float x, y; gs_vector3 wht_pt; if (pcs->personality == pcl5e || pcs->raster_state.graphics_mode) return 0; if (len != 8) return e_Range; x = make_float(pbuff); y = make_float(pbuff + 4); /* * A white point must have a non-zero y value, as otherwise it carries * no chromaticity infomration. It should also have x >= 0, y > 0, and * x + y <= 1, for otherwise it represents an unrealizable color. */ if ((x < 0.0) || (y <= 0.0) || (x + y > 1.0)) return e_Range; wht_pt.u = x / y; wht_pt.v = 1.0; wht_pt.w = (1.0 - x - y) / y; return pcl_palette_set_view_illuminant(pcs, &wht_pt); }
int main() { TEST_SET_START("20040928182549EJL","EJL", "sqrtf4"); unsigned int i3 = 0x742c4455; unsigned int i3r = 0x59d20034; unsigned int i4 = 0x75e7753f; unsigned int i4r = 0x5aac1fb5; unsigned int i5 = 0x4baa9e3c; unsigned int i5r = 0x4593c7d8; unsigned int i6 = 0x39344296; unsigned int i6r = 0x3c56d14c; unsigned int i7 = 0x68a586b0; unsigned int i7r = 0x54118f09; float x3 = hide_float(make_float(i3)); float x3r = hide_float(make_float(i3r)); float x4 = hide_float(make_float(i4)); float x4r = hide_float(make_float(i4r)); float x5 = hide_float(make_float(i5)); float x5r = hide_float(make_float(i5r)); float x6 = hide_float(make_float(i6)); float x6r = hide_float(make_float(i6r)); float x7 = hide_float(make_float(i7)); float x7r = hide_float(make_float(i7r)); vec_float4 x3_v = spu_splats(x3); vec_float4 x3r_v = spu_splats(x3r); vec_float4 x4_v = spu_splats(x4); vec_float4 x4r_v = spu_splats(x4r); vec_float4 x5_v = spu_splats(x5); vec_float4 x5r_v = spu_splats(x5r); vec_float4 x6_v = spu_splats(x6); vec_float4 x6r_v = spu_splats(x6r); vec_float4 x7_v = spu_splats(x7); vec_float4 x7r_v = spu_splats(x7r); vec_float4 res_v; TEST_START("sqrtf4"); res_v = sqrtf4(x3_v); TEST_CHECK("20040928182552EJL", allequal_ulps_float4( res_v, x3r_v, 2 ), 0); res_v = sqrtf4(x4_v); TEST_CHECK("20040928182554EJL", allequal_ulps_float4( res_v, x4r_v, 2 ), 0); res_v = sqrtf4(x5_v); TEST_CHECK("20040928182556EJL", allequal_ulps_float4( res_v, x5r_v, 2 ), 0); res_v = sqrtf4(x6_v); TEST_CHECK("20040928182557EJL", allequal_ulps_float4( res_v, x6r_v, 2 ), 0); res_v = sqrtf4(x7_v); TEST_CHECK("20040928182559EJL", allequal_ulps_float4( res_v, x7r_v, 2 ), 0); TEST_SET_DONE(); TEST_EXIT(); }
int main() { TEST_SET_START("20040928182349EJL","EJL", "rsqrtf4"); unsigned int i3 = 0x742c4455; unsigned int i3r = 0x251c099a; unsigned int i4 = 0x75e7753f; unsigned int i4r = 0x243e5fe2; unsigned int i5 = 0x4baa9e3c; unsigned int i5r = 0x395dbbeb; unsigned int i6 = 0x39344296; unsigned int i6r = 0x429889eb; unsigned int i7 = 0x68a586b0; unsigned int i7r = 0x2ae11e67; float x3 = hide_float(make_float(i3)); float x3r = hide_float(make_float(i3r)); float x4 = hide_float(make_float(i4)); float x4r = hide_float(make_float(i4r)); float x5 = hide_float(make_float(i5)); float x5r = hide_float(make_float(i5r)); float x6 = hide_float(make_float(i6)); float x6r = hide_float(make_float(i6r)); float x7 = hide_float(make_float(i7)); float x7r = hide_float(make_float(i7r)); vec_float4 x3_v = spu_splats(x3); vec_float4 x3r_v = spu_splats(x3r); vec_float4 x4_v = spu_splats(x4); vec_float4 x4r_v = spu_splats(x4r); vec_float4 x5_v = spu_splats(x5); vec_float4 x5r_v = spu_splats(x5r); vec_float4 x6_v = spu_splats(x6); vec_float4 x6r_v = spu_splats(x6r); vec_float4 x7_v = spu_splats(x7); vec_float4 x7r_v = spu_splats(x7r); vec_float4 res_v; TEST_START("rsqrtf4"); res_v = rsqrtf4(x3_v); TEST_CHECK("20040928182352EJL", allequal_ulps_float4( res_v, x3r_v, 2 ), 0); res_v = rsqrtf4(x4_v); TEST_CHECK("20040928182355EJL", allequal_ulps_float4( res_v, x4r_v, 2 ), 0); res_v = rsqrtf4(x5_v); TEST_CHECK("20040928182357EJL", allequal_ulps_float4( res_v, x5r_v, 2 ), 0); res_v = rsqrtf4(x6_v); TEST_CHECK("20040928182358EJL", allequal_ulps_float4( res_v, x6r_v, 2 ), 0); res_v = rsqrtf4(x7_v); TEST_CHECK("20040928182401EJL", allequal_ulps_float4( res_v, x7r_v, 2 ), 0); TEST_SET_DONE(); TEST_EXIT(); }
int main() { TEST_SET_START("20040930102649EJL","EJL", "negatef4"); unsigned int i3n = 0xffffffff; unsigned int i3p = 0x7fffffff; float x0n = hide_float(-0.0f); float x0p = hide_float(0.0f); float x1n = hide_float(-83532.96153153f); float x1p = hide_float(83532.96153153f); float x2n = hide_float(-0.0000000013152f); float x2p = hide_float(0.0000000013152f); float x3n = hide_float(make_float(i3n)); float x3p = hide_float(make_float(i3p)); vec_float4 x0n_v = spu_splats(x0n); vec_float4 x0p_v = spu_splats(x0p); vec_float4 x1n_v = spu_splats(x1n); vec_float4 x1p_v = spu_splats(x1p); vec_float4 x2n_v = spu_splats(x2n); vec_float4 x2p_v = spu_splats(x2p); vec_float4 x3n_v = spu_splats(x3n); vec_float4 x3p_v = spu_splats(x3p); vec_float4 res_v; TEST_START("negatef4"); res_v = negatef4(x0n_v); TEST_CHECK("20040930102652EJL", allequal_float4( res_v, x0p_v ), 0); res_v = negatef4(x0p_v); TEST_CHECK("20040930102653EJL", allequal_float4( res_v, x0n_v ), 0); res_v = negatef4(x1n_v); TEST_CHECK("20040930102655EJL", allequal_float4( res_v, x1p_v ), 0); res_v = negatef4(x1p_v); TEST_CHECK("20040930102657EJL", allequal_float4( res_v, x1n_v ), 0); res_v = negatef4(x2n_v); TEST_CHECK("20040930102659EJL", allequal_float4( res_v, x2p_v ), 0); res_v = negatef4(x2p_v); TEST_CHECK("20040930102701EJL", allequal_float4( res_v, x2n_v ), 0); res_v = negatef4(x3n_v); TEST_CHECK("20040930102703EJL", allequal_float4( res_v, x3p_v ), 0); res_v = negatef4(x3p_v); TEST_CHECK("20040930102705EJL", allequal_float4( res_v, x3n_v ), 0); TEST_SET_DONE(); TEST_EXIT(); }
static _rs_inline obj bignum_to_float(obj x) { mpz_t a; if( FIXNUM_P(x) ) { return make_float( (float) fx2int(x) ); } else if(BIGNUM_P(x)) { OBJ_TO_MPZ(a, x); return make_float(mpz_get_d(a)); } else if( LONG_INT_P(x) ) { return make_float(int_64_to_float( *((INT_64 *)PTR_TO_DATAPTR(x)) )); } scheme_error("bignum_to_float type not found for ~a", 1, x); return FALSE_OBJ; /* not reached */ }
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 value_object eval_aux(expr* node) { if (node == NULL) return make_null(); if (node->type == EXP_ASSIGN) return assign_value(node->left, node->right); value_object left = eval_aux(node->left); value_object right = eval_aux(node->right); switch (node->type) { case EXP_PLUS: return add_values(left, right); case EXP_MINUS: return sub_values(left, right); case EXP_TIMES: return mul_values(left, right); case EXP_DIV: return div_values(left, right); case EXP_INT: return make_int(atoi(node->text)); case EXP_FLOAT: return make_float(to_float64(node->text)); case EXP_NATIVE: return make_native(atof(node->text)); case EXP_CALL: return eval_function(node->text, node->args); case EXP_ID: return get_variable_value(node->text); case EXP_UNMINUS: return negate_value(left); } }
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; }
/* * Convert an array of 32-bit floats from the HP big-endian form into the * native form required by the host processor. */ static void convert_float_array(int num_floats, const byte * pinbuff, float *poutbuff) { while (num_floats-- > 0) { (*poutbuff++) = make_float(pinbuff);; pinbuff += 4; } }
ERL_NIF_TERM enif_make_double(ErlNifEnv* env, double d) { Eterm* hp = alloc_heap(env,FLOAT_SIZE_OBJECT); FloatDef f; f.fd = d; PUT_DOUBLE(f, hp); return make_float(hp); }
/* Returns perl value as a scheme one */ VCSI_OBJECT perl_return(VCSI_CONTEXT vc, SV* val) { if(SvIOK(val)) return make_long(vc,SvIV(val)); else if(SvNOK(val)) return make_float(vc,SvNV(val)); else return make_string(vc,SvPV_nolen(val)); }
static Lisp_Object hash_get_category_set (Lisp_Object table, Lisp_Object category_set) { struct Lisp_Hash_Table *h; ptrdiff_t i; EMACS_UINT hash; if (NILP (XCHAR_TABLE (table)->extras[1])) set_char_table_extras (table, 1, make_hash_table (hashtest_equal, make_number (DEFAULT_HASH_SIZE), make_float (DEFAULT_REHASH_SIZE), make_float (DEFAULT_REHASH_THRESHOLD), Qnil)); h = XHASH_TABLE (XCHAR_TABLE (table)->extras[1]); i = hash_lookup (h, category_set, &hash); if (i >= 0) return HASH_KEY (h, i); hash_put (h, category_set, Qnil, hash); return category_set; }
static Lisp_Object hash_get_category_set (Lisp_Object table, Lisp_Object category_set) { Lisp_Object val; struct Lisp_Hash_Table *h; int i; unsigned hash; if (NILP (XCHAR_TABLE (table)->extras[1])) XCHAR_TABLE (table)->extras[1] = make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE), make_float (DEFAULT_REHASH_SIZE), make_float (DEFAULT_REHASH_THRESHOLD), Qnil, Qnil, Qnil); h = XHASH_TABLE (XCHAR_TABLE (table)->extras[1]); i = hash_lookup (h, category_set, &hash); if (i >= 0) return HASH_KEY (h, i); hash_put (h, category_set, Qnil, hash); return category_set; }
static Lisp_Object make_log (int heap_size, int max_stack_depth) { /* We use a standard Elisp hash-table object, but we use it in a special way. This is OK as long as the object is not exposed to Elisp, i.e. until it is returned by *-profiler-log, after which it can't be used any more. */ Lisp_Object log = make_hash_table (hashtest_profiler, make_number (heap_size), make_float (DEFAULT_REHASH_SIZE), make_float (DEFAULT_REHASH_THRESHOLD), Qnil); struct Lisp_Hash_Table *h = XHASH_TABLE (log); /* What is special about our hash-tables is that the keys are pre-filled with the vectors we'll put in them. */ int i = ASIZE (h->key_and_value) / 2; while (i > 0) set_hash_key_slot (h, --i, Fmake_vector (make_number (max_stack_depth), Qnil)); return log; }
obj float_truncate( IEEE_64 longfloat ) { if ((longfloat >= -536870912.0) && (longfloat <= 536870911.0)) { int t = (int)longfloat; return int2fx( t ); } else if ((longfloat >= -9.22337e+18) && (longfloat <= 9.22337e+18)) { return int_64_compact( float_to_int_64( longfloat ) ); } else { scheme_error( "float_truncate(~d): out of exact range", 1, make_float( longfloat ) ); return FALSE_OBJ; } }
static value_object negate_value(value_object x) { if (x.type == VAL_FLOAT) return make_float(FPL_negate_64(x.float_value)); else if (x.type == VAL_NATIVE) return make_native(- x.native_value); else if (x.type == VAL_INT) return make_int(- x.int_value); else { fprintf(stderr, "Error: trying to negate null\n"); return make_null(); } }
BIF_RETTYPE hipe_bifs_get_hrvtime_0(BIF_ALIST_0) { Eterm *hp; Eterm res; FloatDef f; if (!hrvtime_is_started()) start_hrvtime(); f.fd = get_hrvtime(); hp = HAlloc(BIF_P, FLOAT_SIZE_OBJECT); res = make_float(hp); PUT_DOUBLE(f, hp); BIF_RET(res); }
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); }
static value_object div_values(value_object x, value_object y) { value_type common = coerce(&x, &y); if (common == VAL_NULL) { fprintf(stderr, "Error: trying to divide null objects\n"); return make_null(); } else if (common == VAL_FLOAT) return make_float(FPL_division_64(x.float_value, y.float_value)); else if (common == VAL_NATIVE) return make_native(x.native_value / y.native_value); else return make_int(x.int_value / y.int_value); }
int main() { TEST_SET_START("20040916145017EJL","EJL", "floorf"); unsigned int i3 = 0x4affffff; // 2^23 - 0.5, largest truncatable value. unsigned int i3i = 0x4afffffe; unsigned int i4 = 0x4b000000; // 2^23, no fractional part. unsigned int i5 = 0xcf000001; // -2^31, one more large, and negative, value. float x0 = hide_float(0.91825f); float x0i = hide_float(0.0f); float x1 = hide_float(-0.12958f); float x1i = hide_float(-1.0f); float x2 = hide_float(-79615.1875f); float x2i = hide_float(-79616.0f); float x3 = hide_float(make_float(i3)); float x3i = hide_float(make_float(i3i)); float x4 = hide_float(make_float(i4)); float x4i = hide_float(make_float(i4)); float x5 = hide_float(make_float(i5)); float x5i = hide_float(make_float(i5)); vec_float4 x0_v = vec_splat_float(x0); vec_float4 x0i_v = vec_splat_float(x0i); vec_float4 x1_v = vec_splat_float(x1); vec_float4 x1i_v = vec_splat_float(x1i); vec_float4 x2_v = vec_splat_float(x2); vec_float4 x2i_v = vec_splat_float(x2i); vec_float4 x3_v = vec_splat_float(x3); vec_float4 x3i_v = vec_splat_float(x3i); vec_float4 x4_v = vec_splat_float(x4); vec_float4 x4i_v = vec_splat_float(x4i); vec_float4 x5_v = vec_splat_float(x5); vec_float4 x5i_v = vec_splat_float(x5i); vec_float4 res_v; TEST_START("floorf4"); res_v = floorf4(x0_v); TEST_CHECK("20040916145022EJL", allequal_float4( res_v, x0i_v ), 0); res_v = floorf4(x1_v); TEST_CHECK("20040916145024EJL", allequal_float4( res_v, x1i_v ), 0); res_v = floorf4(x2_v); TEST_CHECK("20040916145027EJL", allequal_float4( res_v, x2i_v ), 0); res_v = floorf4(x3_v); TEST_CHECK("20040916145029EJL", allequal_float4( res_v, x3i_v ), 0); res_v = floorf4(x4_v); TEST_CHECK("20040916145032EJL", allequal_float4( res_v, x4i_v ), 0); res_v = floorf4(x5_v); TEST_CHECK("20040916145034EJL", allequal_float4( res_v, x5i_v ), 0); TEST_SET_DONE(); TEST_EXIT(); }
static emacs_value module_make_float (emacs_env *env, double d) { MODULE_FUNCTION_BEGIN (module_nil); return lisp_to_value (make_float (d)); }
int main() { TEST_SET_START("20040928105926EJL","EJL", "divf4"); unsigned int i0n = 0x75013340; unsigned int i0d = 0x75e7753f; unsigned int i0r = 0x3e8ee64b; unsigned int i1n = 0x4c7fed5a; unsigned int i1d = 0x3a0731f0; unsigned int i1r = 0x51f24e86; unsigned int i2n = 0x5b08b303; unsigned int i2d = 0x562f5046; unsigned int i2r = 0x44479d24; unsigned int i3n = 0x748a9b87; unsigned int i3d = 0x6b014b46; unsigned int i3r = 0x49093864; unsigned int i4n = 0x35dcf9d8; unsigned int i4d = 0x6278d6e0; unsigned int i4r = 0x12e355b5; unsigned int i5n = 0x74d505fd; unsigned int i5d = 0x61ef565e; unsigned int i5r = 0x5263daa3; float x0n = hide_float(make_float(i0n)); float x0d = hide_float(make_float(i0d)); float x0r = hide_float(make_float(i0r)); float x1n = hide_float(make_float(i1n)); float x1d = hide_float(make_float(i1d)); float x1r = hide_float(make_float(i1r)); float x2n = hide_float(make_float(i2n)); float x2d = hide_float(make_float(i2d)); float x2r = hide_float(make_float(i2r)); float x3n = hide_float(make_float(i3n)); float x3d = hide_float(make_float(i3d)); float x3r = hide_float(make_float(i3r)); float x4n = hide_float(make_float(i4n)); float x4d = hide_float(make_float(i4d)); float x4r = hide_float(make_float(i4r)); float x5n = hide_float(make_float(i5n)); float x5d = hide_float(make_float(i5d)); float x5r = hide_float(make_float(i5r)); vec_float4 x0n_v = spu_splats(x0n); vec_float4 x0d_v = spu_splats(x0d); vec_float4 x0r_v = spu_splats(x0r); vec_float4 x1n_v = spu_splats(x1n); vec_float4 x1d_v = spu_splats(x1d); vec_float4 x1r_v = spu_splats(x1r); vec_float4 x2n_v = spu_splats(x2n); vec_float4 x2d_v = spu_splats(x2d); vec_float4 x2r_v = spu_splats(x2r); vec_float4 x3n_v = spu_splats(x3n); vec_float4 x3d_v = spu_splats(x3d); vec_float4 x3r_v = spu_splats(x3r); vec_float4 x4n_v = spu_splats(x4n); vec_float4 x4d_v = spu_splats(x4d); vec_float4 x4r_v = spu_splats(x4r); vec_float4 x5n_v = spu_splats(x5n); vec_float4 x5d_v = spu_splats(x5d); vec_float4 x5r_v = spu_splats(x5r); vec_float4 res_v; TEST_START("divf4"); res_v = divf4(x0n_v, x0d_v); TEST_CHECK("20040928105932EJL", allequal_ulps_float4( res_v, x0r_v, 2 ), 0); res_v = divf4(x1n_v, x1d_v); TEST_CHECK("20040928105934EJL", allequal_ulps_float4( res_v, x1r_v, 2 ), 0); res_v = divf4(x2n_v, x2d_v); TEST_CHECK("20040928105936EJL", allequal_ulps_float4( res_v, x2r_v, 2 ), 0); res_v = divf4(x3n_v, x3d_v); TEST_CHECK("20040928105938EJL", allequal_ulps_float4( res_v, x3r_v, 2 ), 0); res_v = divf4(x4n_v, x4d_v); TEST_CHECK("20040928105940EJL", allequal_ulps_float4( res_v, x4r_v, 2 ), 0); res_v = divf4(x5n_v, x5d_v); TEST_CHECK("20040928105943EJL", allequal_ulps_float4( res_v, x5r_v, 2 ), 0); TEST_SET_DONE(); TEST_EXIT(); }
int main() { TEST_SET_START("20040920142553EJL","EJL", "recipf4"); unsigned int i0r = 0x7fffffff; unsigned int i1 = 0xff000000; // -2^127 unsigned int i2 = 0xfe7fffff; // -2^126 - 1 ulp unsigned int i2r = 0x80800001; unsigned int i3 = 0x75013340; // random values unsigned int i3r = 0x09fd9f35; unsigned int i4 = 0x75e7753f; unsigned int i4r = 0x090d9277; unsigned int i5 = 0x4c7fed5a; unsigned int i5r = 0x32800954; unsigned int i6 = 0x3a0731f0; unsigned int i6r = 0x44f2602e; unsigned int i7 = 0x69784a07; unsigned int i7r = 0x1583f9a3; float x0 = hide_float(0.0f); float x0r = hide_float(make_float(i0r)); float x1 = hide_float(make_float(i1)); float x1r = hide_float(0.0f); float x2 = hide_float(make_float(i2)); float x2r = hide_float(make_float(i2r)); float x3 = hide_float(make_float(i3)); float x3r = hide_float(make_float(i3r)); float x4 = hide_float(make_float(i4)); float x4r = hide_float(make_float(i4r)); float x5 = hide_float(make_float(i5)); float x5r = hide_float(make_float(i5r)); float x6 = hide_float(make_float(i6)); float x6r = hide_float(make_float(i6r)); float x7 = hide_float(make_float(i7)); float x7r = hide_float(make_float(i7r)); vec_float4 x0_v = spu_splats(x0); vec_float4 x0r_v = spu_splats(x0r); vec_float4 x1_v = spu_splats(x1); vec_float4 x1r_v = spu_splats(x1r); vec_float4 x2_v = spu_splats(x2); vec_float4 x2r_v = spu_splats(x2r); vec_float4 x3_v = spu_splats(x3); vec_float4 x3r_v = spu_splats(x3r); vec_float4 x4_v = spu_splats(x4); vec_float4 x4r_v = spu_splats(x4r); vec_float4 x5_v = spu_splats(x5); vec_float4 x5r_v = spu_splats(x5r); vec_float4 x6_v = spu_splats(x6); vec_float4 x6r_v = spu_splats(x6r); vec_float4 x7_v = spu_splats(x7); vec_float4 x7r_v = spu_splats(x7r); vec_float4 res_v; TEST_START("recipf4"); res_v = recipf4(x0_v); TEST_CHECK("20040920142558EJL", allequal_float4( res_v, x0r_v ), 0); res_v = recipf4(x1_v); TEST_CHECK("20040920142600EJL", allequal_float4( res_v, x1r_v), 0); res_v = recipf4(x2_v); TEST_CHECK("20040920142602EJL", allequal_ulps_float4( res_v, x2r_v, 2 ), 0); res_v = recipf4(x3_v); TEST_CHECK("20040920142604EJL", allequal_ulps_float4( res_v, x3r_v, 2 ), 0); res_v = recipf4(x4_v); TEST_CHECK("20040920142606EJL", allequal_ulps_float4( res_v, x4r_v, 2 ), 0); res_v = recipf4(x5_v); TEST_CHECK("20040920142608EJL", allequal_ulps_float4( res_v, x5r_v, 2 ), 0); res_v = recipf4(x6_v); TEST_CHECK("20040920142609EJL", allequal_ulps_float4( res_v, x6r_v, 2 ), 0); res_v = recipf4(x7_v); TEST_CHECK("20040920142611EJL", allequal_ulps_float4( res_v, x7r_v, 2 ), 0); TEST_SET_DONE(); TEST_EXIT(); }
/* Examine some interesting floats */ int main() { float f; int i; for (i = -3; i < 10; i++) { printf("%d:\n ", i); print_float(ldexp(1.0, i)); } for (f = -4 ; f < 4; f += 1) print_float(f); for (f = -.01 ; f < .01; f += .002) print_float(f); f = 1.0/0; print_float(f); f += 1.0; print_float(f); /* Explicitly make a denormal - I've no idea how to create these * with regular calculations: */ make_float(&f, 0, 0, 0x1000); print_float(f); /* It seems you can just specify them! */ f = 5.739719e-42; print_float(f); /* A little, non-denormalized float */ make_float(&f, 0, 1, 0x1); print_float(f); /* A negative little, non-denormalized float */ make_float(&f, 1, 1, 0x1); print_float(f); /* A big float */ make_float(&f, 0, 254, ~0); print_float(f); make_float(&f, 1, 254, ~0); print_float(f); /* Littlest and biggest denormals: */ make_float(&f, 0, 0, 1); print_float(f); make_float(&f, 0, 0, ~0); print_float(f); make_float(&f, 1, 0, 1); print_float(f); make_float(&f, 1, 0, ~0); print_float(f); }
obj string_to_float( char *str_in, UINT_32 len, unsigned radix ) { UINT_8 *str = (UINT_8*)str_in; double x = 0.0, r = radix; double v = 0.0; unsigned i, num_digits = 0; int exp, exp_neg; rs_bool neg = NO; if (*str == '-') { str++; neg = YES; } else if (*str == '+') { str++; } while (*str && *str != '.') { i = digit_value( *str++ ); if (i >= radix) { /* note that this notation cannot be used in radix >= 15 */ if (i == 14) /* e|E */ { goto float_exp; } return FALSE_OBJ; } v = v * radix + i; num_digits++; } if (*str == '.') { str++; r = 1.0 / r; x = r; while (*str) { i = digit_value( *str++ ); if (i >= radix) { if (i == 14) /* e|E */ { goto float_exp; } return FALSE_OBJ; } v += i * x; x *= r; num_digits++; } } if (num_digits == 0) return FALSE_OBJ; /* no digits -- "." is invalid */ return make_float( neg ? -v : v ); float_exp: exp = 0; exp_neg = 0; if (*str == '-') { exp_neg = 1; str++; } else if (*str == '+') { str++; } while (*str) { i = digit_value( *str++ ); if (i >= 10) { /* exponents are always in decimal */ return FALSE_OBJ; } exp = (exp * 10) + i; if (exp > 1000000) return FALSE_OBJ; /* exponent too big! */ } return make_float( (neg ? -v : v) * pow( radix, exp_neg ? -exp : exp ) ); }
static void make_quiet_nan_float(float *dest) { make_float(dest, 0, 255, 1 << 22); }
static void make_signaling_nan_float(float *dest) { make_float(dest, 0, 255, 1); }
static void make_neg_inf_float(float *dest) { make_float(dest, 1, 255, 0); /* or -HUGE_VALF? */ }
static void make_pos_inf_float(float *dest) { make_float(dest, 0, 255, 0); /* or HUGE_VALF? */ }
static void make_denorm_float(float *dest, int sign, int mantissa) { make_float(dest, sign, 0, mantissa); }