How to implement a method that returns the answer to the question: is it true that a + b = c? Permissible error - 0.0001 (1E-4)

Closed due to the fact that off-topic participants freim , insolor , andreymal , Kirill Malyshev , sanmai March 19 at 1:16 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • " Learning tasks are allowed as questions only on condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- freim, andreymal, Kirill Malyshev, sanmai
If the question can be reformulated according to the rules set out in the certificate , edit it .

    2 answers 2

    Here in C:

    return fabs(a+bc) < 1e-4; 

      That's shorter:

       class Main { public static void main(String[] args) { System.out.println(eq(1, 1, 2.00005, 0.0001)); } static boolean eq(double a, double b, double c, double eps) { return Math.abs(a + b - c) < eps; } }