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 ago --- Quote Start --- Use 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. --- Quote End --- Thanks! thats what i ended up finding out after i posted this too! I am actually ok if it uses multipliers. the chip i am using has a lot of hardwires multipliers and i do not need them for anything else. i have it working ok for positive numbers, but i am trying to figure it out for negative numbers. the next set of compares i am trying to do is B < -A*2.41421. i think that would need some more work to figure out how to deal with 2's complement using this system!