hi all,
how can i represent a fractional number in verilog code.i need to store it into a memoryand do some(like addition,sub) operation.
if i do so can i apply it in to a fpga .is it synthesizable ?????
plzz help im confused.
Use a fractional number representation, like floating point format, to store your number. It will be like a normal binary number but with some bits representing the exponent and some representing the fractional part. Just search online for different ways of fractional number representation.
To process these numbers, you will just have to interpret each bit appropriately.
Use a fractional number representation, like floating point format, to store your number. It will be like a normal binary number but with some bits representing the exponent and some representing the fractional part. Just search online for different ways of fractional number representation.
To process these numbers, you will just have to interpret each bit appropriately.
Fixed point arithmetic is synthesizable. As Tricky mention scale everytyhing by some 2^N value, then code your arithmetic as if you were using integers or 2's comp values, depending on if you need unsigned or signed.
Moderately pedantic point: strictly speaking fractional representation is precisely that, fractional. So you have two integer numbers P (numerator) and Q (denominator) and they represent your fractional number P/Q. Rational number and all that. When Q is a power of two that's just a special case. And to make it even more boring and predictable (== useful from an engineering point of view) this power of two is usually fixed. And it's this Q = 2^N that is the scaling factor as mentioned by the previous posters.
And as you may note, all the above doesn't have anything to do with floating point.