Reason about rounding, precision limits, and comparison in floating point so numerical results are predictable. Use when money, physics, aggregation, or any comparison of computed values is involved.
Scanned 9/5/2026
Install to Claude Code
npx -y skills add Amey-Thakur/AI-SKILLS --skill floating-point-behavior --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Floating Point Behavior?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/amey-thakur-floating-point-behavior)More formats (shields.io, HTML) on the badges page.
---
name: floating-point-behavior
description: Reason about rounding, precision limits, and comparison in floating point so numerical results are predictable. Use when money, physics, aggregation, or any comparison of computed values is involved.
---
# Floating point behaviour
Floating point represents most decimal values approximately, which makes
familiar arithmetic laws fail: addition is not associative, equality is
unreliable, and errors accumulate. None of this is a bug, and all of it
surprises people.
## Method
1. **Never use floating point for money.** Use integer minor units or a
decimal type, because a fraction of a cent per transaction becomes a
reconciliation problem (see currency-localization).
2. **Never compare with equality.** Compare within a tolerance
appropriate to the magnitude of the values, since two mathematically
equal computations can differ in the last bits.
3. **Understand that order changes the result.** Summing a large list
gives different answers in different orders, which matters for
reproducibility and for parallel reduction.
4. **Sum small values before large ones.** Adding small numbers to a
large accumulator loses them entirely, and compensated summation
avoids it where accuracy matters.
5. **Watch subtraction of near-equal values.** Cancellation destroys
significant digits and is the main source of catastrophic error in
numerical code.
6. **Know the special values.** Infinity and not-a-number propagate
silently through calculations and compare unusually, so they need
explicit checks.
7. **Choose precision deliberately.** Single precision is faster and
smaller and runs out of significant digits sooner than people expect
(see mixed-precision-deployment).
## Boundaries
These are properties of the representation rather than defects, and they
apply in every language. Decimal types solve the money problem and are
slower. Numerical stability for scientific computing is a specialist
discipline beyond these basics.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!