# Precision error with two mathematically identical expressions around zero

When plotting two mathematically equivalent expressions very close to zero we get two similar results, but one of the curve has steps instead of being smooth.

``````1-cosh(x) == -2*sinh(x/2)^2
``````

Now a quick observation reveals that the height of the step is indeed equal to the precision of Matlab, i.e. the variable `eps = 2.2204e-16 = 2^-52`

This graph was introduced with the name "zero sum", obviously not referencing a zero sum game. But apparently this only occurs with results of additions (or substractions) being very close to zero.

However, to my knowledge calculations with floating point numbers (or doubles) are similar in precision regardless of the scale at which the calculations are being made. So I'd expect error to only creep when something really big is being operated on with something really small, in which case the smaller number gets rounded off.

Matlab code to reproduce this:

``````x = linspace(-5*10^-8, 5*10^-8, 1001);
y1 = @(x) 1 - cosh(x);
y2 = @(x) -2*(sinh(x/2)).^2;

plot(x,y1(x),'k',x,y2(x),'r')
legend('1-cosh(x)', '-2sinh(x/2)^2')
``````

Can someone explain how this.. works?

• You are forgetting that `cosh` and `sinh` are actually numerical function that approximate the real continuous function – Ander Biguri Mar 6 '18 at 13:37

The rounding happens in the `cosh` function. If you plot it and zoom in to the graph at the same scale, you'll see the same staircase-like effect, but centered around 1 on the y-axis.
• Indeed, you can represent 1e-100, but you cannot represent 1+1e-100, which is what the result of `cosh` near 0 is. That one gets rounded to 16 digits, leading to 1.000000000000001 or something like that. Then you subtract the 1. – Cris Luengo Mar 6 '18 at 13:43
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}