Floating-Point And Numeric Precision Bug Review
Detects precision loss, comparison errors, and rounding bugs in numeric and financial code.
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
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
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
Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.
Techniques in this prompt
Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.
Learn this techniqueRecommended models
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
Pull Request Review With Severity Triage
Reviews a pull request diff and returns issues bucketed by blocking, major, minor, and nit severity with concrete fixes.
Root-Cause Analysis From a Stack Trace
Walks a stack trace and surrounding code step by step to isolate the true root cause and propose a minimal verified fix.
Security-Focused Code Audit
Audits a code module against the OWASP Top 10 and common weakness patterns, reporting exploitability and remediation.
Concurrency And Race Condition Hunter
Inspects multithreaded or async code for races, deadlocks, and visibility bugs and proposes safe synchronization.