precision - are computations with large floats less accurate then with small floats -


is statement correct? :

computations large numbers less accurate due logarithmic distribution of floating point numbers on computer.

so means computing values around 1 more accurate (because of rounding errors) same computations each number has been scaled 1e20 example?

short answer:

yes statement correct, larger floating point numbers less precise smaller ones.

details:

floating point numbers have fixed number of bits assigned mantissa. if number being represented requires more bits in mantissa rounded. smaller number can represented more precisely.

to make more concrete wrote following program adds progressively smaller values large floating point number , small one. show difference included double precision floating point not have rounding. double experience same problem if mantissa larger.

#include <stdio.h>  int main() {   float large_float, small_float, epsilon;   double large_double, small_double;    large_float = 1 << 20;   small_float = 1;   epsilon = 0.1;    large_double = large_float;   small_double = small_float;    printf("large_float\t large_double\t small_float\t small_double\t epsilon\n");    for(int = 0; < 10; i++) {     printf("%f\t %f\t %f\t %f\t %f\n", large_float, large_double,small_float, small_double, epsilon);     large_float += epsilon;     large_double += epsilon;     small_float += epsilon;     small_double += epsilon;     epsilon /= 2;           }    return 0; } 

running program produces following output:

large_float      large_double    small_float     small_double    epsilon 1048576.000000   1048576.000000  1.000000        1.000000        0.100000 1048576.125000   1048576.100000  1.100000        1.100000        0.050000 1048576.125000   1048576.150000  1.150000        1.150000        0.025000 1048576.125000   1048576.175000  1.175000        1.175000        0.012500 1048576.125000   1048576.187500  1.187500        1.187500        0.006250 1048576.125000   1048576.193750  1.193750        1.193750        0.003125 1048576.125000   1048576.196875  1.196875        1.196875        0.001563 1048576.125000   1048576.198438  1.198437        1.198438        0.000781 1048576.125000   1048576.199219  1.199219        1.199219        0.000391 1048576.125000   1048576.199609  1.199609        1.199609        0.000195 

as can see large_float value less precise small_float can lead final result less accurate well.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -