How can I convert an IEEE floating point number to a floating point number which has a specified number of exponent bits and mantissa bits using the Fixed Point Blockset 3.1 (R12.1)?
1 view (last 30 days)
Show older comments
I would like to convert an IEEE floating point number to a floating point number which has a specified number of exponent bits and mantissa bits using the Fixed Point Blockset 3.1 (R12.1).
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
Using the Fixed Point Blockset function NUM2FIXPT, any value stored in an IEEE double can be quantized to the value it would have with fewer mantissa bits and fewer exponent bits. For example,
v = num2fixpt( pi, float(9,4) )
v =
3.1250
However, it should be noted that the returned results are still stored in a double.
whos
Name Size Bytes Class
v 1x1 8 double array
Using the hex format, it can be seen that most of the bits have been set to zero.
format hex
v
v =
4009000000000000
However, it is important to note that NUM2FIXPT only quantizes the current value. If you manipulate the quantized result, then the result will have the range and precision of an IEEE double.
For example the following uses up most of the bits in a double:
v/3
ans =
1.04166666666667
To perform calculations at the lower precision, lots of calls to NUM2FIXPT would have to be inserted at the appropriate places. For example:
num2fixpt( v/3, float(9,4) )
ans =
1.06250000000000
0 Comments
More Answers (0)
See Also
Categories
Find more on Fixed Point in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!