How do you convert that to your desired result of. If you multiply 7071 by 8232, you will get the result 58208472. Everything works the same except that there's a different rule for placing the decimal point. How do you turn that result back into a decimal? Well, your answer is 15303 ten-thousandths, so by placing your decimal point in the proper location you get your answer, 1.5303. Now they are integers and you should know how to work with them in verilog. One way to do that is to decide that your variables represent ten-thousandths and proceed from there. Say you decide that you want to store a decimal with four digits past the decimal point. You could do it in fixed point arithmetic. If you want to output it on a VGA monitor directly from the FPGA, then you need to convert that value into individual decimal digits. If you want to send it to a PC over ethernet or uart, then you can just send the values as 1s and 0s, and you can write some software that converts that binary value to ascii and display it on your screen. So the question here is how do you want to use the result? At the end of the day regardless of if it's floating or fixed point or some other representation, the value is just a collection of 1s and 0s. The trick with fixed point is picking the correct number of integer and fractional bits for each stage of your calculation, so that the result has a suitable accuracy, and you don't end up overflowing / underflowing, or ending up at 0 because you had intermediary results that were smaller than the amount of precision you had.īut I can't understand how I would get the final result back to decimal point because verilog doesn't allow real as output. So you can just write: my_fixed1 + my_fixed2, and the result is also a fixed point number. Considering these values as integer: 0101101 (45) + 0001100 (12) = 57 (0111001), adding the decimal point back in at the same place: 0111.001, same value we got before. Multiplication is a little more complex when dealing with signed values, but not much more than integer multiplication. In fact you can treat it as integer addition. The main advantage of fixed point is the maths is simple and cheap. So with Q4.3 you can only represent accuracy up to 1/8. With the above example we would call it Q4.3 (4 bits integer, 3 bits fractional), or some people use Q7.3 (7 bits total, 3 of those are fractional), I'll use the former here. AKA your decimal point is fixed it never moves, you always have (with this example) 4 bits of integer and 3 bits of fractional. Now since you always have the same amount of fractional bits and integer bits whatever size your number is your value always has the same amount of precision. This continues as you move right of the decimal point, for the fractional bit: 1/2, 1/4, 1/8. So as you move right each bit represents half the value of the previous: 8, 4, 2, 1. So as you'd expect your integer part is 0101 = 5. So like when decoding a normal binary integer, you start at the decimal point and work left for the integer part, the first bit is your 1, then your 2, then 4, then 8. Now fixed point is different, you essentially store N bits of integer, and M bits of fraction. Multiplication isn't too bad, but addition is very expensive, and that's one of your most common operations, so that's not great. So your decimal point moves, you have more accuracy (more fractional part) with smaller values than with larger values, hence floating point.įloating point maths is expensive in digital design, it takes a lot of resources to do this maths. Meaning you can represent a large amount of very small numbers, but you loose accuracy with large numbers. Because the mantissa is a constant number of bits, the precision varies with the size of the number. Meaning you can represent very small numbers (. The exponent is stored biased, so you can go from say -127 to +127. Your floating point number contains a sign bit, several bits of mantissa and several bits of exponent. Where M is your "mantissa" (in binary), E is your exponent, and A is 1 or 0, typically 1 for a normal number, but can be 0 for "denormals". In software you often use floating point, where your number is representad as: +/- A.MMMMMM * 2 E. There are several ways to do this, each of which has advantages and disadvantages. Basically you need a way to store a representation of a non integer number.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |