Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21604 Discussions

calculate pi in verilog

Altera_Forum
Honored Contributor II
1,718 Views

Im trying to develop a system which will calculate pi using verilog and using the Gregory Leibniz series. this is the equation  

 

pi = 4 x ( (-1)^n / 2n+1 ); where n = 0 to infinity  

 

ive tried my best but cant seem to go anywhere. i couldnt find any verilog operator that calculates the power of a number, for example (-1)^3.  

another question is, can verilog execute any calculations except binary? for example fractional numbers. if no then how will i implement the above equation? im suposed to implement this into quartus and simulate it. in simulation i only saw an output if my calculation was in binary.i tried to multiply 2 decimal numbers (10 & 12) but i got 0 in output. for binary 10&10 i got 100.  

 

please help me. if any one can provide me with the coding, that will be great or at least the equation coding so that it execute in simulation. 

 

thanks
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
867 Views

As a general comment, it's much more easy to calcúlate it with a regular computer and some algebraic tool, that can handle large numbers. 

 

In a Verilog (or another HDL), you have to select and implement a number scheme first. Verilog knows only signed and unsigned numbers, you have to introduce at least fractional signed numbers to achieve some accuracy. The advantage is, that Verilog numbers aren't a priori limited to a particular bit length, you can extend them to your needs (but within the resource restrictions of your hardware). The (-1)^n is a trivial problem, look sharp!
0 Kudos
Reply