Gast
#2403335
function real Sin;
//input [63:0] x;
//input real x;
input x; // im Bogenmass
real x;
real p,t,r,f;
integer i;
real condition;
begin
p= 1.0;
t= 1.0;
r = 0.0;
i = 0;
f= 1.0;
while( x > 2.0*3.1415926536)
x = x - 2.0*3.1415926536;
while( x < -2.0*3.1415926536)
x = x + 2.0*3.1415926536;
while ( (Abs(t) > 1e-5) || (Abs(r) > 1.0))
begin
t = p / (f);
r = r + Phase4(i) * t;
p = p * x;
i = i + 1;
f = f * i;
if(i == 30) $finish;
// $display(" sin x %e t %e r %e p %e loop i %d f %e ", x,t,r,p,i,f);
end //while
Sin=r;
end
endfunction
////////////////////////////////
function real Real;
input x;
integer x;
begin
Real = x;
end
endfunction
////////////////////////////////
function real Phase4;
input n;
integer n;
integer themod;
begin
themod = mod(n,4);
case(themod)
0: Phase4 = 0.0;
1: Phase4 = 1.0;
2: Phase4 = 0.0;
3: Phase4 = -1.0;
endcase
end
endfunction
////////////////////////////////
function integer mod;
input n,m;
integer n,m;
begin
while(n>=m) begin
n = n-m;
//$display(" mod %d %d", n,m);
end
mod=n;
end
endfunction
/////////////////////////////////
function real Abs ;
input x;
real x;
begin
if(x > 0.0) Abs = x;
else Abs = -1.0*x;
end
endfunction
endmodule