{
  "id": "python/pytest-assert-approx-equality",
  "signature": "AssertionError: assert 0.1 + 0.2 == 0.3; 0.30000000000000004 != 0.3",
  "signature_zh": "断言错误：断言 0.1 + 0.2 == 0.3；0.30000000000000004 != 0.3",
  "regex": "AssertionError:\\ assert\\ 0\\.1\\ \\+\\ 0\\.2\\ ==\\ 0\\.3;\\ 0\\.30000000000000004\\ !=\\ 0\\.3",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Floating-point arithmetic precision issues cause equality assertions to fail when comparing computed floats to expected values.",
  "root_cause_type": "generic",
  "root_cause_zh": "浮点算术精度问题导致在将计算出的浮点数与预期值进行比较时，相等性断言失败。",
  "versions": [
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Rounding the result to a fixed number of decimal places may work for some cases but can mask precision errors in edge cases.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using assertAlmostEqual with a default tolerance may still fail if the tolerance is too small.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Use pytest.approx: assert 0.1 + 0.2 == pytest.approx(0.3, rel=1e-9) or abs=1e-12",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use math.isclose: assert math.isclose(0.1 + 0.2, 0.3, rel_tol=1e-9)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-08-18",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}