# Electrical – how to find square root of a number by using babylonian method

fpgaverilog

how to find the square root of number by using babylonian method equation: Xn+1=1/2(Xn+(s/Xn)) by using verilog code any one help me ……..I have written a code but its not synthesis not running.

``````module squre (
input [15:0] a,
output reg [15:0] x
);
reg [15:0] b;
reg [15:0] y [0:9];
integer i;

initial b=16'd1;

always @(a) begin
y[0]=b;
for (i=0; i<10; i=i+1) begin
y[i+1]= ((y[i]+(a/y[i]))/2);
if (y[i+1]==y[i]) begin
y[9]=y[i];
i=9;
end
end
x=y[9];
end

endmodule
``````

If any problem in program tell me fast. also in this program has to be dividing problem. Tell me how to write the program.

#### Best Answer

Actually, the only thing that prevents synthesis is the `if` statement inside the `for` loop. Without this, the code specifies a perfectly valid, if somewhat large and messy, combinatoral network.

That's assuming that your tools know how to implement the `/` operator as a combinatorial network in the first place.