Forum Discussion
Altera_Forum
Honored Contributor
11 years agoDecimal point arithmetic
Hi, I am trying to do some math involving degrees for my program. I have two values A and B, both 8 bit Std_logic_vector. I need to calculate the angle given by arctan(B/A). Since this is a very expe...
Altera_Forum
Honored Contributor
11 years agoUse fixed point arithmethic with binary numbers.
A binary number with a comma can esaily be seen as an extension fo conventional interger bnary numbers. As example a 4 bit number with a comma in the middle is B1 B0, B(-1) B(-2) the weights of the 4 bits are B1=2 B0=1 B(-1)=0.5 B(-2)=0.25 In this case the number 1001 = 2.25 in decimal. Then you have to convert the constatnts tha you need in binary. In your example the number 2.141421 in binary is 1001101 with a fictious comma before the last digit (100110,1) that is 38.5. By the way I do not suggest to campare B with A*2.41 this would istantiate a multiplier. Check the literature. This is a well addressed topic. You'll find many HW implementations.