LoginSignup

Detect Floating Point Precision Loss (C++)

Asked 24 days agoAnswer 0Votes 1

1

🔍 Detect Floating Point Precision Loss

❓ Problem Statement

In C++, floating-point numbers (e.g., float, double) can lead to precision errors when performing arithmetic operations.

You are given two floating-point numbers a and b, and an expected result expected_sum.
Write a C++ program that checks if the sum of a + b is "almost equal" to expected_sum within a small epsilon tolerance (1e-6).

Return "YES" if it matches, "NO" otherwise.


🔢 Input Format

  • All values are floating-point numbers.

📤 Output Format


✅ Constraints

  • -1e9 <= a, b, expected_sum <= 1e9
  • Use absolute difference for comparison

Detect Floating Point Precision Loss (C++)


0 Answers


Your Answer