Altera_Forum
Honored Contributor
10 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 expensive operation to do in HW, i have been trying to think of ways to optimize this. luckily i do not need the actual angle, i just need to know the range of the angle to within 45 degrees. I just need to approximate the angle to one of the following : 0,45,90,135. to do so, i am checking to see if the angles fall within certain boundaries. if the angle is less than 22.5 then its seen as 0. between 22.5 and 67.5, its seen as 45 and so on.
to do this compare I want to compare B/A with the tan of those angles. so tan 67.5 is 2.41421 for example. so I wanted to compare 'B' and 'A*2.41421'. The challenge I am having is to deal with the decimal point! I want to avoid using FP here for area and latency reasons. Is there a simple way for me to represent these two sides as 'integers' to do this compare and avoid having to use FP hardware! Thank you!