Intel® FPGA University Program
University Program Material, Education Boards, and Laboratory Exercises
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
1079 Discussions

How to use floating-point number in verilog code?

Altera_Forum
Honored Contributor I
2,137 Views

Hi, 

 

I would like to ask anyone here can please teach me how to use floating-point number in verilog code? For example, I got a formula,  

 

y=100*p^(1000/5255); 

 

if I enter p=100000, I want my y value=894 

 

Is it possible to do that in verilog? 

 

Thanks. 

 

Best regard, 

TWK
0 Kudos
3 Replies
Altera_Forum
Honored Contributor I
328 Views

Verilog has very specific rules about how data types (bit widths, signedness, and realness) are propagated through an expression. 

 

Verilog uses integer arithmetic by default when all operands are integers. You can covert to real arithmetic by using real constants writing:  

 

y - 100.0*p^(1000.0/5200.0);
Altera_Forum
Honored Contributor I
328 Views

 

--- Quote Start ---  

Is it possible to do that in verilog? 

--- Quote End ---  

 

It's possible to calculate real expressions at compile time, e.g. for constants, but the code isn't synthesizable.
Altera_Forum
Honored Contributor I
328 Views

If you are using constants you could represent them using binary form. 

 

http://davidcastells.blogspot.com.es/2012/07/floating-point-to-fixed-point-online.html
Reply