MATLAB Answers


How to increase the precision of MATLAB R2015b

Latest activity Commented on by Yair Altman on 11 Feb 2019
how can we increase the precision of MATLAB R 2015b


Sign in to comment.





1 Answer

Answer by John D'Errico
on 9 Feb 2019
Edited by John D'Errico
on 9 Feb 2019
 Accepted Answer

Short answer: You can't.
Longer answer: Y o u c a n ' t d o t h a t. Well, not easily. ;-)
Seriously, there is no floating point data type in MATLAB that is longer than a double, UNLESS you are willing to use one of three choices. That is, you can use the symbolic toolbox, or you can use my VPI toolbox, or you can use my HPF toolbox. The latter toolboxes are found on the File Exchange, for free download.
x = sym(2)^300
x =
x = vpi(2)^300
x =
x = hpf(2,100)^300
x =
So I've created the number 2^300 in three distinct ways there in MATLAB. First, as a symbolic toolbox number. Then as an integer, using my VPI. Finally, as a floating point number in 100 digits of precision, using my HPF. (Ok, I guess you can also use some Java big number tools in MATLAB. They are kind of inconvenient though to use, wthout writing an overlay class to use them. I have actually done that for the BigInteger tools, to create my VPIJ class, which essentially replaces and boosts the speed of VPI.)
import java.math.BigInteger
X = java.math.BigInteger.pow(java.math.BigInteger(2),300)
X =
As a double, this is all you can get, and essentially no more:
format long g
ans =
A serious flaw of all three options is they will be relatively slow. That is, if you want to work in high precision, then expect things to get really slow, since MATLAB is highly optimized to work with doubles, but NOT so for other classes of numbers.
Two other tools already in MATLAB will allow you to work over a slightly larger set of integers than a double will allow. Thus in integer form you can use int64 and uint64. But a double stops at 2^53-1 to represent integers eactly, whereas uint64 goes up only to 2^64-1. Hardly worth the bother for a few more powers of 2.
In the end, you are best off if you learn to do your work in double precision. This is the art and skill of numerical analysis, learning how to do computations without resorting to the lazy but terribly slow solution of high precision.

  1 Comment

John - it would be great if you could post VPIJ on FEX/Github (or somewhere else, as a commercial tool). We've waited a long time for it, and I'm certain that it will be very warmly received.

Sign in to comment.