{
  "schemaVersion": 1,
  "slug": "decimal-to-fraction-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "db09a240748992c130d1a9dcca505b15b7d3d6f4537d15961f420b31d2c74157",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/decimal-to-fraction-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "a_j = ⌊b_j⌋; b_{j+1} = 1 ÷ (b_j − a_j); h_j = a_j h_{j−1} + h_{j−2}",
    "vars": [
      [
        "x",
        "Input decimal (b₀)"
      ],
      [
        "b_j",
        "Value at step j (b₀ = x)"
      ],
      [
        "a_j",
        "Continued-fraction term"
      ],
      [
        "h_j",
        "Numerator convergent"
      ],
      [
        "k_j",
        "Denominator convergent"
      ]
    ],
    "note": "Start b₀ = x with h₋₁=1, h₀=0, k₋₁=0, k₀=1 (same recurrence for k). Stop when k_j > 10⁷, remainder < 10⁻¹², or after 60 terms. Fraction = h_j/k_j; mixed form splits whole and remainder."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "if(!Number.isFinite(value)||Math.abs(value)>1e9)return {numerator:null,denominator:null,whole:null,remainder:null,fraction:null,__error:'inputError'};const x = value; const sign = x < 0 ? -1 : 1; const ax = Math.abs(x); let h1=1,h0=0,k1=0,k0=1,b=ax,guard=0; while(guard++ < 60){ const a=Math.floor(b); let t=h1; h1=a*h1+h0; h0=t; t=k1; k1=a*k1+k0; k0=t; if(k1 > 1e7) break; const frac=b-a; if(frac < 1e-12) break; b=1/frac; } const num = sign*h1, den = k1; const whole = Math.trunc(num/den); const rem = Math.abs(num - whole*den); return { numerator: num, denominator: den, whole, remainder: rem, fraction: den === 1 ? String(num) : (whole !== 0 ? whole + ' ' + rem + '/' + den : num + '/' + den) };",
    "inputs": [
      {
        "name": "value",
        "type": "number",
        "default": 0.375,
        "min": -1000000000,
        "max": 1000000000,
        "step": 0.000001,
        "requiredValue": true
      }
    ],
    "outputs": [
      {
        "name": "fraction",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "numerator",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "denominator",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "whole",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "remainder",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      }
    ],
    "interpret": null
  }
}
