Using the scientific notation 10^6
in an R code (as I customarily do) results in a significantly longer computing time than using the calculator representation 1e6
:
> system.time(for (t in 1:1e7) x=10^6)
utilisateur système écoulé
4.792 0.000 4.281
> system.time(for (t in 1:1e7) x=1e6)
utilisateur système écoulé
0.804 0.000 1.051
> system.time(for (t in 1:1e7) x=exp(6*log(10)))
utilisateur système écoulé
6.301 0.000 5.702
Why is it the case that R recomputes 10^6
in about the same times as it computes exp{6*log(10)}
? I understand the fact that R executes a function when computing 10^6
, but why was it coded this way?
10^6
viaexp(6*log(10))
? – Susy10^6
but it takes as long as usingexp(6*log(10))
. I will rephrase this sentence, thank you. – Soydouble a=1e6;
ordouble a=pow(10,6);
in C++? – Susy