squashing two commits together

---- Commit 1 ----
improve calculation accuracy

Allow using float point arguments to avoid truncation.

Test: Add (4.9, 4.9) should return 10.
Signed-off-by: Sergii Piatakov <sergii.piatakov@globallogic.com>

---- Commit 2 ----
fix truncation error

To convert float to integer the truncation is performed, but the
rounding is expected.

Test: Add (4.9, 4.9) should return 10.
Signed-off-by: Sergii Piatakov <sergii.piatakov@globallogic.com>

Signed-off-by: IO-23 Oleh Shmuliar <hasslesstech@tutanota.com>
This commit is contained in:
Sergii Piatakov 2018-11-15 15:21:34 +02:00 committed by hasslesstech
parent 976f6913db
commit b7e7566c43
Signed by: hasslesstech
GPG Key ID: 09745A46126DDD4C
2 changed files with 5 additions and 5 deletions

View File

@ -1,11 +1,11 @@
#include "calculator.h"
int Calculator::Add (int a, int b)
int Calculator::Add (double a, double b)
{
return a + b;
return a + b + 0.5;
}
int Calculator::Sub (int a, int b)
int Calculator::Sub (double a, double b)
{
return Add (a, -b);
}

View File

@ -4,8 +4,8 @@
class Calculator
{
public:
int Add (int, int);
int Sub (int, int);
int Add (double, double);
int Sub (double, double);
};
#endif//CALCULATOR_H