Not all numbers can be exactly represented in double precision (which is the default numeric data type in MATLAB). The largest consecutive integer possible in floating point format is
which corresponds to 2^53.
What's the distance between p and the next largest representable number?
Thus, the next value that can be represented in double precision is
If we add something smaller than eps(s) to s, the result does not changes -
As you can see, this is a limitation of double precision numbers (IEEE 754 standard).
Alternatively, you can use integers according to the value you have - Data Type - Integers. Note that each integer data types have a limited precision as well. z1=uint64(12646216567629137)
In case the value is so large, that none of the numeric data types can store it exactly, you can use symbolic numbers (Note requires Symbolic Math Toolbox)
z2 = sym('12646216567629137')
Choosing a 20 digit prime number -
z3 = uint64(975319753197531975319)
z3 =
18446744073709551615
As you can see the stored value is not the same as the value provided.
z4 = sym('975319753197531975319')
z4 = 975319753197531975319
When defining symbolic number for a large numerical value, provide the number inside quotation marks.