Clear Filters
Clear Filters

Byte Size of Fixed Point numbers in Matlab

7 views (last 30 days)
Hi,
I am using extensively fixed point representation of numbers. For example:
fixed = fi( 0.567, 1, 16, 15 );
Checking now how many Byte in memory are allocated for the variable fixed, I discovered:
whos
Name Size Bytes Class Attributes
fixed 1x1 324 embedded.fi
I expected a much smaller overhead for such data type, given the fact that I just want to represent a 16 bit number (2Byte).
Why is it so? Are there other better options?
I am asking in order to speed up Monte Carlo simulations.
Thanks
Marco

Accepted Answer

Walter Roberson
Walter Roberson on 12 Jul 2023

embedded.fi are objects that include control information about the representation and the attached behaviour (such as overflow). The overhead for a single such number is a fair bit. However when you have arrays of them then each additional entry would not take up much space.

Fixed point numbers that do not happen to duplicate a hardware numeric format are going to be slower to calculate with on systems that have built-in floating-point hardware. They are best suited for a few cases:

  • extended arithmetic beyond 53 bits of precision
  • hardware such as vhdl or embedded processors that do not have appropriate floating point hardware
  • cases where the attachable behaviour (such as overflow) are important to do differently than the default (there are systems where it is more important that the behaviour be exactly specified rather than as fast as possible)

If you are working on a host system rather than an embedded system, perhaps using a gpu would be better than worrying about memory transfer details.

  3 Comments
Walter Roberson
Walter Roberson on 13 Jul 2023
Occasionally, people ask about using a custom or fixed-point datatype on CPUs, thinking that the smaller storage requirements of the custom or fixed-point type will lead to less memory transfer and so speed up calculation.
The problem with that hypothesis is that in practice, hardware is typed for a small number of different representations, and although smaller data might lead to less transfer to or from main memory, that extra hardware instructions will likely be needed to unpack and manipulate and repack the custom datatype. You then get into questions about whether the reduced memory transfer costs of a smaller datatype are sufficient to offset the increased instructions needed to deal with the custom datatype.

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!