Working as a High-Performance-Computing guy, we tend to default to single-precision floating point numbers (float
or real
) whenever possible. This is because you can perform more operations per second if each operation is individually faster to perform.
One of the more senior people I work with, however, always insists that (when accuracy is required) you should temporarily convert your single-precision data to double-precision in order to perform division. That is:
float a, b;
float ans = ((double)a)/((double)b);
or
real :: a, b, ans
ans = real(dble(a)/dble(b))
depending on the language you're working in. In my opinion, this looks really ugly, and to be honest I don't even know if the answer held in ans
will be more accurate than if you had simply written ans = a/b
in single-point precision.
Can someone tell me whether converting your numbers prior to arithmetic, specifically for performing division, will actually result in a more accurate answer? Would this be a language/compiler specific question, or would this be up to IEEE? With what number values would this accuracy improvement be most noticeable?
Any enlightening comments/answers would be much appreciated.