Hi there, I tried to multiply 1000000000 (9 zeros) and 100000000000000 (14 zeros). The answer ideally should be 1 followed by 23 zeros, but MATLAB is showing 99999999999999992000000.00.
I tried to check by subtracting 1*e23 - 99999999999999992000000.00, the answer was surprisingly zero. This means that 99999999999999992000000.00 is equal to 1*e23.
Can you please explain the reason. Also, I want my answer to display 1 followed by 23 zeros exactly as it has to be. Could you please help me to achieve this.
You need to use the Symbolic Toolbox, or the MATLAB File Exchange contribution "vpi" (John D'Errico)
The immediate problem you are encountering is that 10^23 requires 77 bits to represent, but IEEE 754 double precision floating point numbers have only 53 bits of precision. Switching to uint64() will not work for you because uint64() would have only 64 bits and you need 77 bits.
The largest power of 10 that MATLAB can store exactly in an IEEE 754 double precision number is 10^15.
The largest power of 10 that can be stored exactly in a uint64() unsigned 64 bit integer is 10^18