Can someone briefly explain fixed-point? MATLAB

In summary, the fi() function returns a signed fixed-point object with value v, 16-bit word length, and best-precision fraction length. If you want more significant digits, you should not use this function.
  • #1
mikeph
1,235
18
Hi, I've been through the help files and demos but one question which I can't find the answer to is destroying my confidence with this toolbox.

If I write: a = fi(3336770033), why does it write 3336830976? I can't figure out why it's losing my number. I don't need any moving decimals, all I want to do is multiply this number a few times, and get the result with complete accuracy. 64 bits is not enough so floating point won't do.

Am I using the wrong toolbox for this purpose?

Thanks
 
Physics news on Phys.org
  • #2
Hi MikeyW! :smile:

What you have is 32 bits floating point precision (about 6 significant digits).
Since the default of MATLAB is 64 bits precision, someone must have forced it down somewhere.

How is fi() defined?
Does it perhaps have a "single" precision floating point argument instead of a "double" precision argument?
 
  • #3
According to the documentation, the default word size for the fixed point function fi is 16 bits.

If you want to multiply large numbers and retain full significance then you need the Symbolic Toolbox. I believe Matlab uses MuPad as the engine for its Symbolic Toolbox, which is the same as Mathcad ... I've attached a screenshot from Mathcad - is this what you want to do?
 

Attachments

  • phys - 12 06 09 symbolic multiplication 01.jpg
    phys - 12 06 09 symbolic multiplication 01.jpg
    9 KB · Views: 427
  • #4
Sorry, I was not familiar with the fi() function yet.

From its description:
"fi(v) returns a signed fixed-point object with value v, 16-bit word length, and best-precision fraction length."

It seems to me that 16-bit word length implies at most 5 significant digits.
If you want more significant digits, you should not use this fi() function.

As you can see in your own screenshot, if you don't tell Matlab what to do with the representation of the numbers, it does just fine, showing as many accurate digits as you want.
 
  • #5
I like Serena said:
Sorry, I was not familiar with the fi() function yet.

From its description:
"fi(v) returns a signed fixed-point object with value v, 16-bit word length, and best-precision fraction length."

It seems to me that 16-bit word length implies at most 5 significant digits.
If you want more significant digits, you should not use this fi() function.

As you can see in your own screenshot, if you don't tell Matlab what to do with the representation of the numbers, it does just fine, showing as many accurate digits as you want.
I'm not sure which message you are replying to here, but just in case its mine (because of mention of the screenshot) I just want to make clear that the screenshot is of Mathcad not Matlab. Mathcad has a version of the MuPad symbolic built into it, whereas the MuPad Symbolic Toolbox is an add-on for Matlab. Matlab normally operates at IEEE double floating-point precision giving something like 52 bits for the mantissa? ... or near enough for Government work, I think ... the relevant point being that standard Matlab will hit a precision limit pretty quickly when multiplying large (number of digits) numbers together.
 
  • #6
Hmm, ok, thanks. I'm still not sure why fi(x) doesn't just give x, it's not like it can be limited by the bit size since the (incorrect) 3336830976 is the same length as my input 3336770033.

I'll give the symbolic toolbox a go, thanks.
 
  • #7
MikeyW said:
Hmm, ok, thanks. I'm still not sure why fi(x) doesn't just give x, it's not like it can be limited by the bit size since the (incorrect) 3336830976 is the same length as my input 3336770033.

I'll give the symbolic toolbox a go, thanks.

Look at the two numbers in hex rather than decimal ... you should find that the 'incorrect' number has a string of zeros at the end, implying they've been lost as expected.
 

Related to Can someone briefly explain fixed-point? MATLAB

1. What is a fixed-point in MATLAB?

A fixed-point in MATLAB is a numeric data type that represents a fixed number of bits for the integer and fractional parts of a number. This allows for more efficient storage and computation of numbers with a limited range of values.

2. How is fixed-point implemented in MATLAB?

Fixed-point is implemented in MATLAB by using fixed-point data types, which include fixed-point integers and fixed-point decimals. These data types can be specified when creating variables or as arguments in functions.

3. What are the advantages of using fixed-point in MATLAB?

The main advantage of using fixed-point in MATLAB is improved efficiency in storage and computation. Fixed-point numbers take up less memory compared to floating-point numbers, and operations on fixed-point numbers can be performed faster.

4. Can fixed-point be used for all types of calculations in MATLAB?

No, fixed-point is not suitable for all types of calculations in MATLAB. It is most commonly used for signal processing and control system design, where the range of values is limited and precision is not critical.

5. How do I convert a floating-point number to fixed-point in MATLAB?

To convert a floating-point number to fixed-point in MATLAB, you can use the "fi" function. This function takes in the floating-point number and the desired fixed-point data type as arguments and returns the converted fixed-point number.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
7K
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
17K
Back
Top