An interesting tool to help preserve floating point precision is Herbie (https://herbie.uwplse.org/), which takes an expression as input and outputs an optimized version of it that will retain precision.
The example they give on their site is:
sqrt(x+1) - sqrt(x) => 1/(sqrt(x+1) + sqrt(x))