Search code examples
c++floating-pointprecisionfloating-accuracynumerical-methods

Is it a defect to center a simulation in [0.5, 0.5, 0.5] with a box size of 1?


I am a numerical physicist, and I've seen some simulation codes in my community which use a 3D simulation box with a center in [0.5, 0.5, 0.5] and a normalized length of 1 (so the box coordinates goes from 0. to 1.). In this box a lot of physical computations are performed and generally the best possible precision is required.

I think that doing a such thing can be viewed as a defect, but I would like to have the confirmation of that. I tends to think this is a defect, because as we have more numerical precision near 0., the numerical accuracy is not well balanced in the whole box.

To have a good balance I think that such a box :

  • should be centered around 0. (going from -0.5 to 0.5) if one wants a symmetric accuracy around the center of the box
  • should be centered around 1.5 (going from 1. to 2.) if one wants a quasi-homogeneous accuracy in the entire box

Am I correct or completely wrong ?


Solution

  • You are correct.

    The precision from 1.0 to 2.0 will be uniform across the surface, like you are using fixed point.

    The precision from -0.5 to 0.5 will be highest around the center point, and lower near the edges (but still quite good).

    The precision from 0.0 to 1.0 will be highest around the (0.0, 0.0) corner and lowest around the (1.0, 1.0) corner, so it will behave in a slightly non-uniform manner.