Different results between 2013a 32bit and 64bit in single precision
Afficher commentaires plus anciens
I am squaring and summing two numbers in single precision, yet I get different results (one bit) between Matlab 32bit and Matlab 64bit on the same Win64 PC. Moreover, I get different results in Matlab 32bit between multiple implementations of this same equation...
Can anyone offer some insight?
Code to reproduce:
format hex
a = single([-0.1113907,0.64]);
%Method 1 (wrong on 32bit?)
r1 = a(1)^2 + a(2)^2
%Method 2 (wrong on 32bit?)
r2 = a(1)*a(1) + a(2)*a(2)
%Method 3 (correct)
tmp1 = a(1)^2; tmp2 = a(2)^2;
r3 = tmp1 + tmp2
%Method 4 (correct)
r4 = sum(a.^2)
Matlab 32bit results:
r1 =
3ed8116a
r2 =
3ed8116a
r3 =
3ed8116b
r4 =
3ed8116b
Matlab 64bit results:
r1 =
3ed8116b
r2 =
3ed8116b
r3 =
3ed8116b
r4 =
3ed8116b
Réponse acceptée
Plus de réponses (1)
Ken Atwell
le 21 Août 2013
1 vote
32-bit and 64-bit versions of MATLAB may use registers of differing widths as related in this 64-bit migration page, with single being called out as being particularly sensitive.
I forget the details, but it may have something to due with legacy 80-bit registers that are perhaps not used by 64-bit versions of MATLAB. 64-bit floating point is said to be more consistent that 32-bit floating point. Your compiler may or may not produce different answers depending on its implementation and the compilation flags you pass to it.
1 commentaire
Jonathan Currie
le 21 Août 2013
Catégories
En savoir plus sur Profile and Improve Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!