module: non_neg_double_to_int
parameters: int b, int beta
inputs: double in, double clk
outputs:  int out
static_variables: 
int mask_b
int mask_error
int mask_out
classes: EdgeDetect clkedge()
init: 
if (b > 32 || b < 1)
  {
   printf("error in 'non_neg_double_to_int':  must have 1 <= b <= 32\n");
   printf("   in this case, b = %d\n",b);
   exit(1);
 }
if (beta > b || beta < 0)
  {
   printf("error in 'non_neg_double_to_int':  must have 0 <= beta <= b\n");
   printf("   in this case, beta = %d, b = %d\n",beta,b);
   exit(1);
 }
if (b == 32) 
   mask_b = ~0;
else
   mask_b = (1 << b) - 1;
mask_error = (1 << beta) - 1;
mask_out = mask_b ^ mask_error;
code:
int int_part, frac_part;
if (clkedge.inp(clk))
   {
   if (in < 0.0)
      {
       printf("error in 'non_neg_double_to_int':  input values must >= 0.0\n");
       printf("  in this case, in = %5.3e\n",in);
       exit(1);
      }
   int_part = (int) floor(in);
   frac_part = (int) ((in - floor(in))*((double) (1<< beta)));
   out = frac_part + (int_part << beta);
   if ((out & (~mask_b)) != 0)
      {
       printf("error in 'non_neg_double_to_int':  output values must\n");
       printf("      be constrained to 'b = %d bits'\n",b);
       printf("in = %5.3e, integer counterpart = %s\n",in,bit_print(out));
       exit(1);
      }
   }
