# VNX-1339: Insufficient Precision or Accuracy of a Real Number

Reports exact equality or inequality comparisons (==, !=, ===, !==) with a decimal literal that binary floating point cannot represent exactly (0.1, 0.3.

| Field | Value |
|---|---|
| Rule ID | `VNX-1339` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | Python, JavaScript / TypeScript, Java, Go |
| CWE | [CWE-1339](https://cwe.mitre.org/data/definitions/1339.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:L/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L` |
| Tags | `float-precision` `floating-point` `correctness` `cwe-1339` |
| Source | [`internal/sast/rules/vnx-1339.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-1339.rego) |

## Overview

VNX-1339 maps to [CWE-1339: Insufficient Precision or Accuracy of a Real Number](https://cwe.mitre.org/data/definitions/1339.html). Most decimal fractions (0.1, 0.3, 19.99) have no exact binary floating-point representation. A computed value is almost never bit-identical to the rounded literal, so `total == 0.3` is false for `0.1 + 0.2`, and a branch guarded that way silently never runs (or a `!=` loop never ends).

## Why this matters

Exact float comparisons in prices, discounts, rates and balances produce wrong totals, skipped promotions and infinite loops. In financial or safety logic the error is a correctness bug that an attacker can sometimes steer by choosing amounts.

## What gets flagged

```python
if total == 0.3:              # FLAGGED
while balance != 0.1:         # FLAGGED
if 0.7 == ratio:              # FLAGGED
```

```javascript
if (sum === 0.3) { ... }      // FLAGGED
```

```java
if (rate == 0.05) { ... }     // FLAGGED
return amount != 19.99f;      // FLAGGED
```

```go
if price*0.9 == 8.99 { ... }  // FLAGGED
```

## What is not flagged

- Literals that are exact in binary: `0.5`, `0.25`, `0.125`, `1.0`, `0.0`, `2.75`.
- Exponent forms (`1e-3`), ordering comparisons (`<`, `<=`, `>`, `>=`).
- Comparisons through a tolerance: `math.isclose`, `pytest.approx`, `toBeCloseTo`, `assertAlmostEqual`, `abs(a - b) < eps`.
- Strings (versions, IP addresses), comments and test files.
- Operand types are not known, so an integer variable compared with a fractional literal is also reported.

## Remediation

1. Compare with a tolerance: `math.isclose(a, b, rel_tol=1e-9)`, `Math.abs(a - b) < EPS`.
2. For money, use a decimal type (`decimal.Decimal`, `BigDecimal`) or integer minor units (cents).

## References

- [CWE-1339: Insufficient Precision or Accuracy of a Real Number](https://cwe.mitre.org/data/definitions/1339.html)
- [What Every Computer Scientist Should Know About Floating-Point Arithmetic](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-1339
// nosec vnx-1339
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-1339 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
