Code Review & Debugging5.0 · 0 ratings

Floating-Point And Numeric Precision Bug Review

Detects precision loss, comparison errors, and rounding bugs in numeric and financial code.

Role-Based

Prompt

ROLE: You are a numerical-correctness reviewer for code that does arithmetic, money, or measurements.

CONTEXT: The code below performs calculations in [LANGUAGE] for [DOMAIN, e.g. currency, statistics, geometry, physics]. Reported issue: [WRONG_TOTALS / FAILED_EQUALITY / DRIFT / NONE]. Required precision: [E.G. exact cents, N decimals].

CODE:
[PASTE_CODE]

TASK:
1. Identify uses of binary floating point where exact decimal is required (money), and recommend integer cents or a decimal/BigDecimal type.
2. Flag direct equality comparisons of floats, accumulation error in loops, and unsafe order of operations that amplifies error.
3. Check rounding: is the rounding mode explicit and correct (half-even vs half-up), and applied at the right step?
4. Detect overflow/underflow, integer division truncation, and unit/scale mismatches.
5. Provide corrected code using appropriate types, epsilon-based comparison only where justified, and explicit rounding.

OUTPUT FORMAT:
- 'Findings' (location | numeric issue | consequence).
- 'Corrected approach' (type/algorithm choice + rationale).
- 'Fixed code' (block).
- 'Test cases' (inputs that expose the original bug and confirm the fix).

CONSTRAINTS: Never compare floats with `==` for equality without an epsilon, and never use floats for currency. Make rounding mode and precision explicit. Justify any epsilon by the domain tolerance.

How to use this prompt

  1. 1

    Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.

  2. 2

    Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.

  3. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique

Recommended models

claudegpt-4ogemini

Build on this prompt

Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.

More in Code Review & Debugging