data/full_repos/permissive/447976230/fpga/usrp2/models/math_real.v
1: b"%Error: data/full_repos/permissive/447976230/fpga/usrp2/models/math_real.v:144: syntax error, unexpected var, expecting IDENTIFIER\n      input real var ;\n                 ^~~\n%Error: data/full_repos/permissive/447976230/fpga/usrp2/models/math_real.v:158: syntax error, unexpected var, expecting ')'\n         gaussian = mean + sqrt((-2.0*log(s))/s) * v1 * sqrt(var) ;\n                                                             ^~~\n%Error: Exiting due to 2 error(s)\n"
module math_real ;


   localparam MATH_E            =  2.7182818284;
   localparam MATH_1_OVER_E     =  0.3678794411;
   localparam MATH_PI           =  3.1415926536;
   localparam MATH_2_PI         =  6.2831853071;
   localparam MATH_1_OVER_PI    =  0.3183098861;
   localparam MATH_PI_OVER_2    =  1.5707963267;
   localparam MATH_PI_OVER_3    =  1.0471975511;
   localparam MATH_PI_OVER_4    =  0.7853981633;
   localparam MATH_3_PI_OVER_2  =  4.7123889803;
   localparam MATH_LOG_OF_2     =  0.6931471805;
   localparam MATH_LOG_OF_10    =  2.3025850929;
   localparam MATH_LOG2_OF_E    =  1.4426950408;
   localparam MATH_LOG10_OF_E   =  0.4342944819;
   localparam MATH_SQRT_2       =  1.4142135623;
   localparam MATH_1_OVER_SQRT_2=  0.7071067811;
   localparam MATH_SQRT_PI      =  1.7724538509;
   localparam MATH_DEG_TO_RAD   =  0.0174532925;
   localparam MATH_RAD_TO_DEG   =  57.2957795130;


   localparam EXPLOG_ITERATIONS =  19;
   localparam COS_ITERATIONS    =  8;
   

    

   function real sign ;
      input real x ;
      begin
         sign = x < 0.0 ? 1.0 : 0.0 ;
      end
   endfunction
   

   function real trunc ;
      input real x ;
      begin
         trunc = x - mod(x,1.0) ;
      end
   endfunction
   

   function real ceil ;
      input real x ;
      real retval ;
      begin
         retval = mod(x,1.0) ;
         if( retval != 0.0 && x > 0.0 )  retval = x+1.0 ;
         else retval = x ;
         ceil = trunc(retval) ;
      end
   endfunction
   

   function real floor ;
      input real x ;
      real retval ;
      begin
         retval = mod(x,1.0) ;
         if( retval != 0.0 && x < 0.0 ) retval = x - 1.0 ;
         else retval = x ;
         floor = trunc(retval) ;
      end
   endfunction
   

   function real round ;
      input real x ;
      real retval ;
      begin
         retval = x > 0.0 ? x + 0.5 : x - 0.5 ;
         round = trunc(retval) ;
      end
   endfunction
   

   function real mod ;
      input real x ;
      input real m ;
      real retval ;
      begin
         retval = x ;
         if( retval > m ) begin
            while( retval > m ) begin
               retval = retval - m ;
            end
         end
         else begin
            while( retval < -m ) begin
               retval = retval + m ;
            end
         end
         mod = retval ;
      end
   endfunction
   

   function real realmax ;
      input real x ;
      input real y ;
      begin
         realmax = x > y ? x : y ;
      end
   endfunction
   

   function real realmin ;
      input real x ;
      input real y ;
      begin
         realmin = x > y ? y : x ;
      end
   endfunction
   

   

   function real gaussian ;
      input real mean ;
      input real var ;
      real u1, u2, v1, v2, s ;
      begin
         s = 1.0 ;
         while( s >= 1.0  ) begin

            u1 = $random/4294967296.0 + 0.5 ;
            u2 = $random/4294967296.0 + 0.5 ;

            v1 = 2*u1-1.0 ;
            v2 = 2*u2-1.0 ;

            s = (v1*v1 + v2*v2) ;
         end
         gaussian = mean + sqrt((-2.0*log(s))/s) * v1 * sqrt(var) ;

      end
   endfunction
   

   

   function real sqrt ;
      input real x ;
      real retval ;
      begin
         sqrt = (x == 0.0) ? 0.0 : powr(x,0.5) ;
      end
   endfunction
   

   function real cbrt ;
      input real x ;
      real retval ;
      begin
         cbrt = (x == 0.0) ? 0.0 : powr(x,1.0/3.0) ;
      end
   endfunction
   

   function real abs ;
      input real x ;
      begin
         abs = (x > 0.0) ? x : -x ;
      end
   endfunction 
   

   function real pow ;
      input real b ;
      input integer x ;
      integer absx ;
      real retval ;
      begin
         retval = 1.0 ;
         absx = abs(x) ;
         repeat(absx) begin
            retval = b*retval ;
         end
         pow = x < 0 ? (1.0/retval) : retval ;
      end
   endfunction
   

   function real powr ;
      input real b ;
      input real x ;
      begin
         powr = exp(x*log(b)) ;
      end
   endfunction
   


   function real exp ;
      input real x ;
      real retval ;
      integer i ;
      real nm1_fact ;
      real powm1 ;
      begin
         nm1_fact = 1.0 ;
         powm1 = 1.0 ;
         retval = 1.0 ;
         for( i = 1 ; i < EXPLOG_ITERATIONS ; i = i + 1 ) begin
            powm1 = x*powm1 ;
            nm1_fact = nm1_fact * i ;
            retval = retval + powm1/nm1_fact ;
         end
         exp = retval ;
      end
   endfunction
   

   function real log ;
      input real x ;
      integer i ;
      real whole ;
      real xm1oxp1 ;
      real retval ;
      real newx ;
      begin
         retval = 0.0 ;
         whole = 0.0 ;
         newx = x ;
         while( newx > MATH_E ) begin
            whole = whole + 1.0 ;
            newx = newx / MATH_E ;
         end
         xm1oxp1 = (newx-1.0)/(newx+1.0) ;
         for( i = 0 ; i < EXPLOG_ITERATIONS ; i = i + 1 ) begin
            retval = retval + pow(xm1oxp1,2*i+1)/(2.0*i+1.0) ;
         end
         log = whole+2.0*retval ;
      end
   endfunction
   

   function real ln ;
      input real x ;
      begin
         ln = log(x) ;
      end
   endfunction
   

   function real log2 ;
      input real x ;
      begin
         log2 = log(x)/MATH_LOG_OF_2 ;
      end
   endfunction
   
   function real log10 ;
      input real x ;
      begin
         log10 = log(x)/MATH_LOG_OF_10 ;
      end
   endfunction
   
   function real log_base ;
      input real x ;
      input real b ;
      begin
         log_base = log(x)/log(b) ;
      end
   endfunction
   

   

   function real reduce ;
      input real x ;
      real retval ;
      begin
         retval = x ;
         while( abs(retval) > MATH_PI ) begin
            retval = retval > MATH_PI ? 
                     (retval - MATH_2_PI) : 
                     (retval + MATH_2_PI) ;
         end
         reduce = retval ;
      end
   endfunction
   

   function real cos ;
      input real x ;
      integer i ;
      integer sign ;
      real newx ;
      real retval ;
      real xsqnm1 ;
      real twonm1fact ;
      begin
         newx = reduce(x) ;
         xsqnm1 = 1.0 ;
         twonm1fact = 1.0 ;
         retval = 1.0 ;
         for( i = 1 ; i < COS_ITERATIONS ; i = i + 1 ) begin
            sign = -2*(i % 2)+1 ;
            xsqnm1 = xsqnm1*newx*newx ;
            twonm1fact = twonm1fact * (2.0*i) * (2.0*i-1.0) ;
            retval = retval + sign*(xsqnm1/twonm1fact) ; 
         end
         cos = retval ;
      end
   endfunction
   

   function real sin ;
      input real x ;
      begin
         sin = cos(x - MATH_PI_OVER_2) ;
      end
   endfunction
   

   function real tan ;
      input real x ;
      begin
         tan = sin(x) / cos(x) ;
      end
   endfunction
   

   function real arcsin ;
      input real x ;
      begin
         arcsin = 2.0*arctan(x/(1.0+sqrt(1.0-x*x))) ;
      end
   endfunction
   

   function real arccos ;
      input real x ;
      begin
         arccos = MATH_PI_OVER_2-arcsin(x) ;
      end
   endfunction
   


   function real arctan ;
      input real x ;
      real retval ;
      real y ;
      real newx ;
      real twoiotwoip1 ;
      integer i ;
      integer mult ;
      begin
         retval = 1.0 ;
         twoiotwoip1 = 1.0 ;
         mult = 1 ;
         newx = abs(x) ;
         while( newx > 1.0 ) begin
            mult = mult*2 ;
            newx = newx/(1.0+sqrt(1.0+newx*newx)) ;
         end
         y = 1.0 ;
         for( i = 1 ; i < 2*COS_ITERATIONS ; i = i + 1 ) begin
            y = y*((newx*newx)/(1+newx*newx)) ;
            twoiotwoip1 = twoiotwoip1 * (2.0*i)/(2.0*i+1.0) ;
            retval = retval + twoiotwoip1*y ;
         end
         retval = retval * (newx/(1+newx*newx)) ;
         retval = retval * mult ;
         
         arctan = (x > 0.0) ? retval : -retval ;
      end
   endfunction
   


   function real arctan_xy ;
      input real x ;
      input real y ;
      real retval ;
      begin
         retval = 0.0 ;
         if( x < 0.0 ) retval = MATH_PI - arctan(-abs(y)/x) ;
         else if( x > 0.0 ) retval = arctan(abs(y)/x) ;
         else if( x == 0.0 ) retval = MATH_PI_OVER_2 ;
         arctan_xy = (y < 0.0) ? -retval : retval ;
      end
   endfunction
   

   

   function real sinh ;
      input real x ;
      begin
         sinh = (exp(x) - exp(-x))/2.0 ;
      end
   endfunction
   

   function real cosh ;
      input real x ;
      begin
         cosh = (exp(x) + exp(-x))/2.0 ;
      end
   endfunction
   

   function real tanh ;
      input real x ;
      real e2x ;
      begin
         e2x = exp(2.0*x) ;
         tanh = (e2x+1.0)/(e2x-1.0) ;
      end
   endfunction
   

   function real arcsinh ;
      input real x ;
      begin
         arcsinh = log(x+sqrt(x*x+1.0)) ;
      end
   endfunction
   

   function real arccosh ;
      input real x ;
      begin
         arccosh = ln(x+sqrt(x*x-1.0)) ;
      end
   endfunction
   

   function real arctanh ;
      input real x ;
      begin
         arctanh = 0.5*ln((1.0+x)/(1.0-x)) ;
      end
   endfunction

   
endmodule
module math_real ;



   localparam MATH_E            =  2.7182818284;
   localparam MATH_1_OVER_E     =  0.3678794411;
   localparam MATH_PI           =  3.1415926536;
   localparam MATH_2_PI         =  6.2831853071;
   localparam MATH_1_OVER_PI    =  0.3183098861;
   localparam MATH_PI_OVER_2    =  1.5707963267;
   localparam MATH_PI_OVER_3    =  1.0471975511;
   localparam MATH_PI_OVER_4    =  0.7853981633;
   localparam MATH_3_PI_OVER_2  =  4.7123889803;
   localparam MATH_LOG_OF_2     =  0.6931471805;
   localparam MATH_LOG_OF_10    =  2.3025850929;
   localparam MATH_LOG2_OF_E    =  1.4426950408;
   localparam MATH_LOG10_OF_E   =  0.4342944819;
   localparam MATH_SQRT_2       =  1.4142135623;
   localparam MATH_1_OVER_SQRT_2=  0.7071067811;
   localparam MATH_SQRT_PI      =  1.7724538509;
   localparam MATH_DEG_TO_RAD   =  0.0174532925;
   localparam MATH_RAD_TO_DEG   =  57.2957795130;


   localparam EXPLOG_ITERATIONS =  19;
   localparam COS_ITERATIONS    =  8;
   

    

   function real sign ;
      input real x ;
      begin
         sign = x < 0.0 ? 1.0 : 0.0 ;
      end
   endfunction
   

   function real trunc ;
      input real x ;
      begin
         trunc = x - mod(x,1.0) ;
      end
   endfunction
   

   function real ceil ;
      input real x ;
      real retval ;
      begin
         retval = mod(x,1.0) ;
         if( retval != 0.0 && x > 0.0 )  retval = x+1.0 ;
         else retval = x ;
         ceil = trunc(retval) ;
      end
   endfunction
   

   function real floor ;
      input real x ;
      real retval ;
      begin
         retval = mod(x,1.0) ;
         if( retval != 0.0 && x < 0.0 ) retval = x - 1.0 ;
         else retval = x ;
         floor = trunc(retval) ;
      end
   endfunction
   

   function real round ;
      input real x ;
      real retval ;
      begin
         retval = x > 0.0 ? x + 0.5 : x - 0.5 ;
         round = trunc(retval) ;
      end
   endfunction
   

   function real mod ;
      input real x ;
      input real m ;
      real retval ;
      begin
         retval = x ;
         if( retval > m ) begin
            while( retval > m ) begin
               retval = retval - m ;
            end
         end
         else begin
            while( retval < -m ) begin
               retval = retval + m ;
            end
         end
         mod = retval ;
      end
   endfunction
   

   function real realmax ;
      input real x ;
      input real y ;
      begin
         realmax = x > y ? x : y ;
      end
   endfunction
   

   function real realmin ;
      input real x ;
      input real y ;
      begin
         realmin = x > y ? y : x ;
      end
   endfunction
   

   

   function real gaussian ;
      input real mean ;
      input real var ;
      real u1, u2, v1, v2, s ;
      begin
         s = 1.0 ;
         while( s >= 1.0  ) begin

            u1 = $random/4294967296.0 + 0.5 ;
            u2 = $random/4294967296.0 + 0.5 ;

            v1 = 2*u1-1.0 ;
            v2 = 2*u2-1.0 ;

            s = (v1*v1 + v2*v2) ;
         end
         gaussian = mean + sqrt((-2.0*log(s))/s) * v1 * sqrt(var) ;

      end
   endfunction
   

   

   function real sqrt ;
      input real x ;
      real retval ;
      begin
         sqrt = (x == 0.0) ? 0.0 : powr(x,0.5) ;
      end
   endfunction
   

   function real cbrt ;
      input real x ;
      real retval ;
      begin
         cbrt = (x == 0.0) ? 0.0 : powr(x,1.0/3.0) ;
      end
   endfunction
   

   function real abs ;
      input real x ;
      begin
         abs = (x > 0.0) ? x : -x ;
      end
   endfunction 
   

   function real pow ;
      input real b ;
      input integer x ;
      integer absx ;
      real retval ;
      begin
         retval = 1.0 ;
         absx = abs(x) ;
         repeat(absx) begin
            retval = b*retval ;
         end
         pow = x < 0 ? (1.0/retval) : retval ;
      end
   endfunction
   

   function real powr ;
      input real b ;
      input real x ;
      begin
         powr = exp(x*log(b)) ;
      end
   endfunction
   


   function real exp ;
      input real x ;
      real retval ;
      integer i ;
      real nm1_fact ;
      real powm1 ;
      begin
         nm1_fact = 1.0 ;
         powm1 = 1.0 ;
         retval = 1.0 ;
         for( i = 1 ; i < EXPLOG_ITERATIONS ; i = i + 1 ) begin
            powm1 = x*powm1 ;
            nm1_fact = nm1_fact * i ;
            retval = retval + powm1/nm1_fact ;
         end
         exp = retval ;
      end
   endfunction
   

   function real log ;
      input real x ;
      integer i ;
      real whole ;
      real xm1oxp1 ;
      real retval ;
      real newx ;
      begin
         retval = 0.0 ;
         whole = 0.0 ;
         newx = x ;
         while( newx > MATH_E ) begin
            whole = whole + 1.0 ;
            newx = newx / MATH_E ;
         end
         xm1oxp1 = (newx-1.0)/(newx+1.0) ;
         for( i = 0 ; i < EXPLOG_ITERATIONS ; i = i + 1 ) begin
            retval = retval + pow(xm1oxp1,2*i+1)/(2.0*i+1.0) ;
         end
         log = whole+2.0*retval ;
      end
   endfunction
   

   function real ln ;
      input real x ;
      begin
         ln = log(x) ;
      end
   endfunction
   

   function real log2 ;
      input real x ;
      begin
         log2 = log(x)/MATH_LOG_OF_2 ;
      end
   endfunction
   
   function real log10 ;
      input real x ;
      begin
         log10 = log(x)/MATH_LOG_OF_10 ;
      end
   endfunction
   
   function real log_base ;
      input real x ;
      input real b ;
      begin
         log_base = log(x)/log(b) ;
      end
   endfunction
   

   

   function real reduce ;
      input real x ;
      real retval ;
      begin
         retval = x ;
         while( abs(retval) > MATH_PI ) begin
            retval = retval > MATH_PI ? 
                     (retval - MATH_2_PI) : 
                     (retval + MATH_2_PI) ;
         end
         reduce = retval ;
      end
   endfunction
   

   function real cos ;
      input real x ;
      integer i ;
      integer sign ;
      real newx ;
      real retval ;
      real xsqnm1 ;
      real twonm1fact ;
      begin
         newx = reduce(x) ;
         xsqnm1 = 1.0 ;
         twonm1fact = 1.0 ;
         retval = 1.0 ;
         for( i = 1 ; i < COS_ITERATIONS ; i = i + 1 ) begin
            sign = -2*(i % 2)+1 ;
            xsqnm1 = xsqnm1*newx*newx ;
            twonm1fact = twonm1fact * (2.0*i) * (2.0*i-1.0) ;
            retval = retval + sign*(xsqnm1/twonm1fact) ; 
         end
         cos = retval ;
      end
   endfunction
   

   function real sin ;
      input real x ;
      begin
         sin = cos(x - MATH_PI_OVER_2) ;
      end
   endfunction
   

   function real tan ;
      input real x ;
      begin
         tan = sin(x) / cos(x) ;
      end
   endfunction
   

   function real arcsin ;
      input real x ;
      begin
         arcsin = 2.0*arctan(x/(1.0+sqrt(1.0-x*x))) ;
      end
   endfunction
   

   function real arccos ;
      input real x ;
      begin
         arccos = MATH_PI_OVER_2-arcsin(x) ;
      end
   endfunction
   


   function real arctan ;
      input real x ;
      real retval ;
      real y ;
      real newx ;
      real twoiotwoip1 ;
      integer i ;
      integer mult ;
      begin
         retval = 1.0 ;
         twoiotwoip1 = 1.0 ;
         mult = 1 ;
         newx = abs(x) ;
         while( newx > 1.0 ) begin
            mult = mult*2 ;
            newx = newx/(1.0+sqrt(1.0+newx*newx)) ;
         end
         y = 1.0 ;
         for( i = 1 ; i < 2*COS_ITERATIONS ; i = i + 1 ) begin
            y = y*((newx*newx)/(1+newx*newx)) ;
            twoiotwoip1 = twoiotwoip1 * (2.0*i)/(2.0*i+1.0) ;
            retval = retval + twoiotwoip1*y ;
         end
         retval = retval * (newx/(1+newx*newx)) ;
         retval = retval * mult ;
         
         arctan = (x > 0.0) ? retval : -retval ;
      end
   endfunction
   


   function real arctan_xy ;
      input real x ;
      input real y ;
      real retval ;
      begin
         retval = 0.0 ;
         if( x < 0.0 ) retval = MATH_PI - arctan(-abs(y)/x) ;
         else if( x > 0.0 ) retval = arctan(abs(y)/x) ;
         else if( x == 0.0 ) retval = MATH_PI_OVER_2 ;
         arctan_xy = (y < 0.0) ? -retval : retval ;
      end
   endfunction
   

   

   function real sinh ;
      input real x ;
      begin
         sinh = (exp(x) - exp(-x))/2.0 ;
      end
   endfunction
   

   function real cosh ;
      input real x ;
      begin
         cosh = (exp(x) + exp(-x))/2.0 ;
      end
   endfunction
   

   function real tanh ;
      input real x ;
      real e2x ;
      begin
         e2x = exp(2.0*x) ;
         tanh = (e2x+1.0)/(e2x-1.0) ;
      end
   endfunction
   

   function real arcsinh ;
      input real x ;
      begin
         arcsinh = log(x+sqrt(x*x+1.0)) ;
      end
   endfunction
   

   function real arccosh ;
      input real x ;
      begin
         arccosh = ln(x+sqrt(x*x-1.0)) ;
      end
   endfunction
   

   function real arctanh ;
      input real x ;
      begin
         arctanh = 0.5*ln((1.0+x)/(1.0-x)) ;
      end
   endfunction

   
endmodule