# How to estimate floating-point precision of function?

Page 1 of 1

## 0 Replies - 936 Views - Last Post: 25 May 2017 - 04:24 PM

### #1 Tapulator

Reputation: 0
• Posts: 1
• Joined: 25-May 17

# How to estimate floating-point precision of function?

Posted 25 May 2017 - 04:24 PM

Dear dream.in.code community,

this is a kind of x-post to my question on the Computer Science Stack Exchange that ran cold. The problem was that I didn't ask precisely enough at first because I didn't really know what I was writing about.

For your convenience I'll give you an improved version including my current answers. Would you mind to verify?

Initial situation: I have a function that consists solely of floating-point operations where the last operation rounds the computed values to a predefined number of digits. I feed this function with floats out of a certain range.

Question: How do I estimate - just by evaluating the sequence of floating-point calculations - that the round-up errors may or may not yield an unexpected result?

My (invalid?) answer: I worked out the following method based on the formulars in this article and will describe how I applied it on my use case.

Example:

```// Pseudo code! Floats conform to IEEE 547.

function main() {
float x, y; // Real value between 199 and 684
x = some_value;
y = another_value;
res_x = calc(x);
res_y = calc(y);
res = res_x + res_y;
return round(res); // Rounds to 2nd decimal
}

function calc(a) {
float b = yet_another_value; // Real value between 1 and 1.4
return a * b;
}

```

Estimation:

• As I'm using IEEE 547 floats, the machine epsilon ε is 1.1e-16.
• The relative error δ of main() is 2ε.
• So the absolute error of my maximal input emax won't exceed 3.8304e-13. *
• That means the result will be precise up to the 12th decimal.
• Since round() has a precision of 2, the calculation does work precisely enough.

*) emax = 2ε * resmax = 2 * 1.1e-16 * 2 * 684 * 1.4 = 3.8304e-13.

Bonus question: Would one add up the results of calc() infinitely, how many (n) results would be "needed" approximately to contaminate the rounded total?

My (invalid?) bonus answer: One would have to call calc() at least 4 trillion times!

• e has to be at least 0.001 to force a round-up error
• The maximum result of calc() is xmax = 684 * 1.4 = 957.6
• e = δ * x => x = e / δ = e / 2ε = 1e-3 / (2 * 1.1e-16) = 1e+13 / 2.2
• n = x / xmax = 1e+13 / (2.2 * 957.6) ≈ 4e+9

It would be great if you comment on my thoughts. I don't know what I'm doing.

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }