## Epsilon

Post here if you don't find any other place for your post. But please, stay on-topic: algorithms, programming or something related to this web site and its services.

Moderator: Board moderators

jiban
New poster
Posts: 1
Joined: Sun Aug 01, 2010 1:20 pm

### Epsilon

Can anyone tell me when I have to use epsilon rounding in floating point numbers ? What's the meaning of "The Judge data is prepared such that any good solution can use epsilon from 10^-7 to 10^-13" this kind of statements?

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

### Re: Epsilon

Floating point types have a finite precision, and so they typically represent values with some round-off error. You should add/subtract some small value (epsilon) during comparison of floats in order to tolerate this error. E.g. instead of "a < b", it's better to write "a < b - EPS", and instead of "a <= b" - "a < b + EPS".
What's the meaning of "The Judge data is prepared such that any good solution can use epsilon from 10^-7 to 10^-13" this kind of statements?
It probably only means that the judges have a solution which managed to produce the correct output using epsilon values in this range.

You can't pick an epsilon too small, because of underflow. if you're using a double type, it has a precision for about 15-16 digits (e.g. 1 + 1e-16 == 1), and so you can't pick an epsilon that's 10^15 - 10^16 times smaller than the magnitude of values that you're going to be dealing with.

And you obviously can't pick a large epsilon, or your program will start to behave incorrectly.

zobayer
Experienced poster
Posts: 110
Joined: Tue May 06, 2008 2:18 pm
Contact:

### Re: Epsilon

for double type, sometimes 0 is printed -0, idk why, but adding EPS with output helps to avoid it.
You should not always say what you know, but you should always know what you say.

Ranier
New poster
Posts: 1
Joined: Sun Apr 17, 2016 2:40 pm

### Re: Epsilon

mf wrote:Floating point types have a finite precision, and so they typically represent values with some round-off error. You should add/subtract some small value (epsilon) during comparison of floats in order to tolerate this error. E.g. instead of "a < b", it's better to write "a < b - EPS", and instead of "a <= b" - "a < b + EPS".
What's the meaning of "The Judge data is prepared such that any good solution can use epsilon from 10^-7 to 10^-13" this kind of statements?
It probably only means that the judges have a solution which managed to produce the correct output using epsilon values in this range.

You can't pick an epsilon too small, because of underflow. if you're using a double type, it has a precision for about 15-16 digits (e.g. 1 + 1e-16 == 1), and so you can't https://dudehung.com/vigrx-plus-review-results-2016 the VigRx Plus stuff with an epsilon that's 10^15 - 10^16 times smaller than the magnitude of values that you're going to be dealing with.

And you obviously can't pick a large epsilon, or your program will start to behave incorrectly.
Thanks MF, this made a lot of sense and was helpful as I was struggling with epsilon rounding.