|
ustunozgur <ustunozgur@gmail.com> wrote in message <7e2e0d2d-b779-4137-92f5-8b4b2807764f@g23g2000yqh.googlegroups.com>...
> a = 100^100; str2num(num2str(a)) == a
>
> results in 1
>
> but
>
> num2str(a) =
> 99999999999999996973312221251036165947450327545502362648241750950346848435554075
> 53419633840470625186802751241597388240818213573436827848463938504104723987787102
> 3591066789981811181813306167128854888448
>
>
> Howcome? What is the best way to deal with such large numbers in
> MATLAB? How can I see the number without num2str function?
>
You're dealing with floating-point roundoff. The result you're getting from
num2str is O(eps) different than 100^100, in terms of relative error.
If you need a 200+ digit number, with all digits represented, don't use floating-point.
Use VPA.
x = vpa ('100^100', 210)
Alternatively, use fprintf
fprintf ('%32.18g\n', 100^100);
which reports 1e+200.
|