double RNG::nfix(slong h, ulong i) { const double r = 3.442620; // The starting of the right tail double x, y; for(;;) { x = h * wn[i]; // If i == 0, handle the base strip if (i == 0) { do { x = -log(rand_open01()) * 0.2904764; // .2904764 is 1/r y = -log(rand_open01()); } while (y + y < x * x); return ((h > 0) ? r + x : -r - x); } // If i > 0, handle the wedges of other strips if (fn[i] + rand_open01() * (fn[i - 1] - fn[i]) < exp(-.5 * x * x)) return x; // start all over h = UL32toSL32(rand_int32()); i = h & 127; if (ULONG32(std::abs(h)) < kn[i]) return (h * wn[i]); } } // RNG::nfix
static int test_int32(void) { int i; avro_schema_t writer_schema = avro_schema_int(); for (i = 0; i < 100; i++) { avro_datum_t datum = avro_int32(rand_int32()); write_read_check(writer_schema, NULL, datum, "int"); avro_datum_decref(datum); } avro_schema_decref(writer_schema); return 0; }
double RNG::efix(ulong j, ulong i) { for (;;) { if (i == 0) return (7.69711 - log(rand_open01())); const double x = j * we[i]; if (fe[i] + rand_open01() * (fe[i - 1] - fe[i]) < exp(-x)) return x; j = rand_int32(); i = (j & 255); if (j < ke[i]) return (j * we[i]); } } // RNG::efix
static int test_int32(void) { int i; avro_schema_t writer_schema = avro_schema_int(); avro_schema_t long_schema = avro_schema_long(); avro_schema_t float_schema = avro_schema_float(); avro_schema_t double_schema = avro_schema_double(); for (i = 0; i < 100; i++) { int32_t value = rand_int32(); avro_datum_t datum = avro_int32(value); avro_datum_t long_datum = avro_int64(value); avro_datum_t float_datum = avro_float(value); avro_datum_t double_datum = avro_double(value); write_read_check(writer_schema, datum, NULL, NULL, "int"); write_read_check(writer_schema, datum, long_schema, long_datum, "int->long"); write_read_check(writer_schema, datum, float_schema, float_datum, "int->float"); write_read_check(writer_schema, datum, double_schema, double_datum, "int->double"); avro_datum_decref(datum); avro_datum_decref(long_datum); avro_datum_decref(float_datum); avro_datum_decref(double_datum); } avro_datum_t datum = avro_int32(10000); test_json(datum, "10000"); avro_datum_decref(datum); avro_schema_decref(writer_schema); avro_schema_decref(long_schema); avro_schema_decref(float_schema); avro_schema_decref(double_schema); return 0; }