{
  "id": "python/pytest-approx-comparison-fail",
  "signature": "AssertionError: assert 0.1 + 0.2 == 0.3\n +  where 0.1 + 0.2 = 0.30000000000000004",
  "signature_zh": "断言错误：断言 0.1 + 0.2 == 0.3\n + 其中 0.1 + 0.2 = 0.30000000000000004",
  "regex": "AssertionError:\\ assert\\ 0\\.1\\ \\+\\ 0\\.2\\ ==\\ 0\\.3\\\n\\ \\+\\ \\ where\\ 0\\.1\\ \\+\\ 0\\.2\\ =\\ 0\\.30000000000000004",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Floating-point arithmetic precision issues cause the sum of 0.1 and 0.2 to be slightly off from 0.3, leading to a failed equality assertion.",
  "root_cause_type": "generic",
  "root_cause_zh": "浮点运算精度问题导致0.1和0.2的和与0.3略有偏差，导致相等性断言失败。",
  "versions": [
    {
      "version": "7.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Rounding the result to a fixed number of decimal places",
      "why_fails": "This may mask real precision issues in other calculations and is not a general solution.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using assert 0.1 + 0.2 == 0.3 with a tolerance check manually",
      "why_fails": "This is error-prone and less readable than using pytest.approx.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use pytest.approx for floating-point comparisons",
      "success_rate": 0.95,
      "how": "from pytest import approx\nassert 0.1 + 0.2 == approx(0.3)\nThis uses a default relative tolerance of 1e-6.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Specify a custom tolerance with approx",
      "success_rate": 0.9,
      "how": "assert 0.1 + 0.2 == approx(0.3, rel=1e-9, abs=1e-12)\nThis allows fine-grained control over the comparison.",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-04-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}