/* step */ void random_step(ubx_block_t *b) { unsigned int rand_val; struct rnd_info* inf; inf=(struct rnd_info*) b->private_data; ubx_port_t* rand_port = ubx_port_get(b, "rnd"); rand_val = random(); rand_val = (rand_val > inf->info.max) ? (rand_val%inf->info.max) : rand_val; rand_val = (rand_val < inf->info.min) ? ((inf->info.min + rand_val)%inf->info.max) : rand_val; write_rnd(rand_port, &rand_val); }
int gsl_ieee_set_mode (int precision, int rounding, int exception_mask) { unsigned long int mode = 0 ; unsigned int rnd = 0 ; /* I'm actually not completely sure that the alpha only supports default * precisions rounding, but I couldn't find any information regarding this, so * it seems safe to assume this for now until it's proven otherwise. */ switch (precision) { case GSL_IEEE_SINGLE_PRECISION: GSL_ERROR ("Tru64 Unix on the alpha only supports default precision rounding", GSL_EUNSUP) ; break ; case GSL_IEEE_DOUBLE_PRECISION: GSL_ERROR ("Tru64 Unix on the alpha only supports default precision rounding", GSL_EUNSUP) ; break ; case GSL_IEEE_EXTENDED_PRECISION: GSL_ERROR ("Tru64 Unix on the alpha only supports default precision rounding", GSL_EUNSUP) ; break ; } switch (rounding) { case GSL_IEEE_ROUND_TO_NEAREST: rnd = FP_RND_RN ; write_rnd (rnd) ; break ; case GSL_IEEE_ROUND_DOWN: rnd = FP_RND_RM ; write_rnd (rnd) ; break ; case GSL_IEEE_ROUND_UP: rnd = FP_RND_RP ; write_rnd (rnd) ; break ; case GSL_IEEE_ROUND_TO_ZERO: rnd = FP_RND_RZ ; write_rnd (rnd) ; break ; default: rnd = FP_RND_RN ; write_rnd (rnd) ; } /* Turn on all the exceptions apart from 'inexact' */ /* from the ieee(3) man page: * IEEE_TRAP_ENABLE_INV -> Invalid operation * IEEE_TRAP_ENABLE_DZE -> Divide by 0 * IEEE_TRAP_ENABLE_OVF -> Overflow * IEEE_TRAP_ENABLE_UNF -> Underflow * IEEE_TRAP_ENABLE_INE -> Inexact (requires special option to C compiler) * IEEE_TRAP_ENABLE_DNO -> denormal operand * Note: IEEE_TRAP_ENABLE_DNO is not supported on OSF 3.x or Digital Unix * 4.0 - 4.0d(?). * IEEE_TRAP_ENABLE_MASK -> mask of all the trap enables * IEEE_MAP_DMZ -> map denormal inputs to zero * IEEE_MAP_UMZ -> map underflow results to zero */ mode = IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF | IEEE_TRAP_ENABLE_UNF ; if (exception_mask & GSL_IEEE_MASK_INVALID) mode &= ~ IEEE_TRAP_ENABLE_INV ; if (exception_mask & GSL_IEEE_MASK_DENORMALIZED) { #ifdef IEEE_TRAP_ENABLE_DNO mode &= ~ IEEE_TRAP_ENABLE_DNO ; #else GSL_ERROR ("Sorry, this version of Digital Unix does not support denormalized operands", GSL_EUNSUP) ; #endif } if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO) mode &= ~ IEEE_TRAP_ENABLE_DZE ; if (exception_mask & GSL_IEEE_MASK_OVERFLOW) mode &= ~ IEEE_TRAP_ENABLE_OVF ; if (exception_mask & GSL_IEEE_MASK_UNDERFLOW) mode &= ~ IEEE_TRAP_ENABLE_UNF ; if (exception_mask & GSL_IEEE_TRAP_INEXACT) { /* To implement this would require a special flag to the C compiler which can cause degraded performance */ GSL_ERROR ("Sorry, GSL does not implement trap-inexact for Tru64 Unix on the alpha - see fp-tru64.c for details", GSL_EUNSUP) ; /* In case you need to add it, the appropriate line would be * * mode |= IEEE_TRAP_ENABLE_INE ; * */ } else { mode &= ~ IEEE_TRAP_ENABLE_INE ; } ieee_set_fp_control (mode) ; return GSL_SUCCESS ; }