//              COPYRIGHT T.R.BARBOUR 1995. All rights reserved.
//              =============================================== 
                                                                
#include "emath.h"
#include "stdlib.h"

static Ioserror err("emath");

uint twoto(uint exp) {
	prc0(exp < sizeof(uint) * 8);
	return (1 << exp);
}
uint bitrev(uint x, uint nbits) {
	prc0(nbits < sizeof(uint) * 8);
	uint inbit = 1, outbit = twoto(nbits - 1), res =0;
	for(uint i = 0; i < nbits; i++, inbit <<= 1, outbit >>= 1)
	  res|= (x & inbit ? outbit : 0);
	return res;
}
float randomFloat() {
   return ((float)random() / ((float)RAND_MAX + (float)1.0));
}
double randomDouble() {
   return ((double)random() / ((double)RAND_MAX + (double)1.0));
}
uint randomTo(uint sup) {
   return (uint)((double)sup * randomDouble());
}
double log(double base, double x) {
   prc0(base > 0);
   prc0(x > 0);
   return ( log(x)/log(base) );
}
