Skip to main content
added 1327 characters in body
Source Link
Roman
  • 50.6k
  • 2
  • 61
  • 136

To get a feeling for the inaccuracies in IEEE 754 double-precision floating-point numbers, have a look at how the number $10^{50}$ is represented in this form:

x = N[10^50]
(*    1.*10^50    *)

SetPrecision[x, ∞]
(*    100000000000000007629769841091887003294964970946560    *)

So the number $10^{50}$ has been modified by the finite internal representation of machine numbers to be about $10^{50}+7.62977\times10^{33}$. There simply aren't more bits available to do a better job.

Naturally, calculating the sine of this number has nothing to do with calculating the sine of $10^{50}$.

This is approximately what is going on when doing this kind of machine-precision calculations.

Let's do a bit of stochastic math (with a physics spin) on top of this. Converting an exact number $x$ to a machine-precision floating point number $\tilde{x}$ always brings a relative error of about $\pm2^{-54}$. In the absence of more details, let's assume that this relative error has a Gaussian distribution of mean $x$ and standard deviation $\sigma=x\delta$ (with $\delta\approx 2^{-54}$):

$$ p(\tilde{x})=\frac{1}{x\delta\sqrt{2\pi}}e^{-\frac{(\tilde{x}/x-1)^2}{2\delta^2}} $$

Calculating $\sin(x)$ can then proceed over this distribution:

$$ \langle\sin(\tilde{x})\rangle=\int_{-\infty}^{\infty}\sin(\tilde{x})p(\tilde{x})d\tilde{x} = \sin(x)\cdot e^{-\frac12x^2\delta^2} $$

This means that the expected result $\sin(x)$ is attenuated (smeared out) by the uncertainty factor $e^{-\frac12x^2\delta^2}$. In your case, with $x=10^{50}$ and $\delta\approx2^{-54}$, we get

E^(-1/2 x^2 δ^2) /. {x -> 10^50, δ -> 2^-54}
(*    1/E^(7888609052210118054117285652827862296732064351090230047702789306640625/512)    *)

Log[10, %] // N
(*    -6.69137*10^66    *)

This is a very small number, about $10^{-6.69\times10^{66}}$. So there is absolutely no chance that you'll be getting the right answer $\sin(x)$ from this calculation.

To get a feeling for the inaccuracies in IEEE 754 double-precision floating-point numbers, have a look at how the number $10^{50}$ is represented in this form:

x = N[10^50]
(*    1.*10^50    *)

SetPrecision[x, ∞]
(*    100000000000000007629769841091887003294964970946560    *)

So the number $10^{50}$ has been modified by the finite internal representation of machine numbers to be about $10^{50}+7.62977\times10^{33}$. There simply aren't more bits available to do a better job.

Naturally, calculating the sine of this number has nothing to do with calculating the sine of $10^{50}$.

This is approximately what is going on when doing this kind of machine-precision calculations.

To get a feeling for the inaccuracies in IEEE 754 double-precision floating-point numbers, have a look at how the number $10^{50}$ is represented in this form:

x = N[10^50]
(*    1.*10^50    *)

SetPrecision[x, ∞]
(*    100000000000000007629769841091887003294964970946560    *)

So the number $10^{50}$ has been modified by the finite internal representation of machine numbers to be about $10^{50}+7.62977\times10^{33}$. There simply aren't more bits available to do a better job.

Naturally, calculating the sine of this number has nothing to do with calculating the sine of $10^{50}$.

This is approximately what is going on when doing this kind of machine-precision calculations.

Let's do a bit of stochastic math (with a physics spin) on top of this. Converting an exact number $x$ to a machine-precision floating point number $\tilde{x}$ always brings a relative error of about $\pm2^{-54}$. In the absence of more details, let's assume that this relative error has a Gaussian distribution of mean $x$ and standard deviation $\sigma=x\delta$ (with $\delta\approx 2^{-54}$):

$$ p(\tilde{x})=\frac{1}{x\delta\sqrt{2\pi}}e^{-\frac{(\tilde{x}/x-1)^2}{2\delta^2}} $$

Calculating $\sin(x)$ can then proceed over this distribution:

$$ \langle\sin(\tilde{x})\rangle=\int_{-\infty}^{\infty}\sin(\tilde{x})p(\tilde{x})d\tilde{x} = \sin(x)\cdot e^{-\frac12x^2\delta^2} $$

This means that the expected result $\sin(x)$ is attenuated (smeared out) by the uncertainty factor $e^{-\frac12x^2\delta^2}$. In your case, with $x=10^{50}$ and $\delta\approx2^{-54}$, we get

E^(-1/2 x^2 δ^2) /. {x -> 10^50, δ -> 2^-54}
(*    1/E^(7888609052210118054117285652827862296732064351090230047702789306640625/512)    *)

Log[10, %] // N
(*    -6.69137*10^66    *)

This is a very small number, about $10^{-6.69\times10^{66}}$. So there is absolutely no chance that you'll be getting the right answer $\sin(x)$ from this calculation.

Source Link
Roman
  • 50.6k
  • 2
  • 61
  • 136

To get a feeling for the inaccuracies in IEEE 754 double-precision floating-point numbers, have a look at how the number $10^{50}$ is represented in this form:

x = N[10^50]
(*    1.*10^50    *)

SetPrecision[x, ∞]
(*    100000000000000007629769841091887003294964970946560    *)

So the number $10^{50}$ has been modified by the finite internal representation of machine numbers to be about $10^{50}+7.62977\times10^{33}$. There simply aren't more bits available to do a better job.

Naturally, calculating the sine of this number has nothing to do with calculating the sine of $10^{50}$.

This is approximately what is going on when doing this kind of machine-precision calculations.