{
  "schemaVersion": 1,
  "slug": "data-storage-calculator",
  "category": "conversion",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "8d0dc61f8c253e9f65a7a2324d19894e3033a31f30302c021e526dbddba47291",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/data-storage-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": "Q_d = Q × 1000^(p_f − p_t); Q_b = Q × 1024^(p_f − p_t)",
    "vars": [
      [
        "Q",
        "Value"
      ],
      [
        "p_f",
        "Source exponent"
      ],
      [
        "p_t",
        "Target exponent"
      ],
      [
        "Q_d",
        "Decimal result"
      ],
      [
        "Q_b",
        "Binary result"
      ]
    ],
    "note": "Exponents: B=0, kB=1, MB=2, GB=3, TB=4, PB=5. Bytes = Q×1000^p_f; GiB = Q×1024^(p_f−3)."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-28",
    "sources": [
      {
        "name": "NIST — Binary prefixes and decimal storage units",
        "url": "https://physics.nist.gov/cuu/Units/binary.html"
      }
    ],
    "referenceRole": "definition",
    "implementationHash": "8d0dc61f8c253e9f65a7a2324d19894e3033a31f30302c021e526dbddba47291",
    "basis": "Q_d = Q × 1000^(p_f − p_t); Q_b = Q × 1024^(p_f − p_t) P1 consolidation retains the core model and adds input modes or derived outputs. The migration report records the input/output union and known-answer checks.",
    "limitations": "The references explain definitions and methods; any extra preset must be checked against the assumptions on this page. Added display totals and migration adapters are implementation behavior, not independently validated claims."
  },
  "contract": {
    "compute": "const mergedResult=(()=>{if((true&&![\"gb\", \"b\", \"kb\", \"mb\", \"tb\", \"pb\", \"kib\", \"mib\", \"gib\", \"tib\", \"pib\"].includes(String(from)))||(true&&![\"mb\", \"b\", \"kb\", \"gb\", \"tb\", \"pb\", \"kib\", \"mib\", \"gib\", \"tib\", \"pib\"].includes(String(to)))||(true&&![\"0\", \"2\", \"4\", \"6\"].includes(String(precision)))||(true&&![\"general\", \"exact\"].includes(String(bytePolicy))))return{__error:'inputError'};\nif((true&&(!Number.isFinite(value)||value<0||value>9007199254740991)))return{__error:'inputError'};\nconst F={\"b\":1,\"kb\":1000,\"mb\":1000000,\"gb\":1000000000,\"tb\":1000000000000,\"pb\":1000000000000000,\"kib\":1024,\"mib\":1048576,\"gib\":1073741824,\"tib\":1099511627776,\"pib\":1125899906842624},U={\"b\":\"B\",\"kb\":\"kB\",\"mb\":\"MB\",\"gb\":\"GB\",\"tb\":\"TB\",\"pb\":\"PB\",\"kib\":\"KiB\",\"mib\":\"MiB\",\"gib\":\"GiB\",\"tib\":\"TiB\",\"pib\":\"PiB\"};if(!Number.isFinite(value)||value<0||value>9007199254740991||!['general','exact'].includes(bytePolicy)||!Object.prototype.hasOwnProperty.call(U,from)||!Object.prototype.hasOwnProperty.call(U,to))return {\"result\":null,\"decimal\":null,\"binary\":null,\"bytes\":null,\"gib\":null,\"__error\":\"inputError\"};let size=value*F[from];if(bytePolicy==='exact'){const rounded=Math.round(size);if(from!=='b'&&Math.abs(size-rounded)<=Math.abs(size)*Number.EPSILON*2)size=rounded;if(!Number.isSafeInteger(size)||size<0)return{result:null,decimal:null,binary:null,bytes:null,gib:null,__error:'inputError'};}const P={b:0,kb:1,mb:2,gb:3,tb:4,pb:5,kib:1,mib:2,gib:3,tib:4,pib:5};return {mib:size/1048576,tb:size/1e12,gb:size/1e9,mb:size/1e6,kb:size/1000,result:size/F[to],decimal:size/F[to],binary:size/Math.pow(1024,P[to]),bytes:size,gib:size/1073741824,__resultUnit:U[to],__binaryUnit:['B','KiB','MiB','GiB','TiB','PiB'][P[to]],__unitRatio:F[to]/F[from]};\n})();return mergedResult.__error?{\"result\":null,\"decimal\":null,\"binary\":null,\"bytes\":null,\"gib\":null,\"kb\":null,\"mb\":null,\"gb\":null,\"tb\":null,\"mib\":null,...mergedResult}:mergedResult;",
    "inputs": [
      {
        "name": "value",
        "type": "number",
        "default": 1,
        "min": 0,
        "max": 9007199254740991,
        "step": 0.01,
        "requiredValue": true,
        "strictRange": true
      },
      {
        "name": "from",
        "type": "select",
        "default": "gb",
        "options": [
          {
            "value": "gb"
          },
          {
            "value": "b"
          },
          {
            "value": "kb"
          },
          {
            "value": "mb"
          },
          {
            "value": "tb"
          },
          {
            "value": "pb"
          },
          {
            "value": "kib"
          },
          {
            "value": "mib"
          },
          {
            "value": "gib"
          },
          {
            "value": "tib"
          },
          {
            "value": "pib"
          }
        ]
      },
      {
        "name": "to",
        "type": "select",
        "default": "mb",
        "options": [
          {
            "value": "mb"
          },
          {
            "value": "b"
          },
          {
            "value": "kb"
          },
          {
            "value": "gb"
          },
          {
            "value": "tb"
          },
          {
            "value": "pb"
          },
          {
            "value": "kib"
          },
          {
            "value": "mib"
          },
          {
            "value": "gib"
          },
          {
            "value": "tib"
          },
          {
            "value": "pib"
          }
        ]
      },
      {
        "name": "precision",
        "type": "select",
        "default": 4,
        "options": [
          {
            "value": 0
          },
          {
            "value": 2
          },
          {
            "value": 4
          },
          {
            "value": 6
          }
        ]
      },
      {
        "name": "bytePolicy",
        "type": "select",
        "default": "general",
        "options": [
          {
            "value": "general"
          },
          {
            "value": "exact"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "result",
        "precision": 4,
        "precisionField": "precision",
        "unitField": "__resultUnit",
        "trimTrailingZeros": true,
        "notation": "auto"
      },
      {
        "name": "decimal",
        "precision": 6,
        "unit": "",
        "showWhen": {
          "to": []
        },
        "notation": "auto"
      },
      {
        "name": "binary",
        "precision": 6,
        "unit": "",
        "unitField": "__binaryUnit",
        "notation": "auto",
        "showWhen": {
          "to": [
            "kb",
            "mb",
            "gb",
            "tb",
            "pb"
          ]
        }
      },
      {
        "name": "bytes",
        "precision": 0,
        "unit": "B",
        "showWhen": {
          "to": [
            "kb",
            "mb",
            "gb",
            "tb",
            "pb",
            "kib",
            "mib",
            "gib",
            "tib",
            "pib"
          ]
        },
        "notation": "auto"
      },
      {
        "name": "gib",
        "precision": 6,
        "unit": "GiB",
        "showWhen": {
          "to": [
            "b",
            "kb",
            "mb",
            "tb",
            "pb",
            "kib",
            "mib",
            "tib",
            "pib"
          ]
        },
        "notation": "auto"
      },
      {
        "name": "kb",
        "precision": 6,
        "unit": "kB",
        "notation": "auto",
        "showWhen": {
          "bytePolicy": [
            "exact"
          ]
        }
      },
      {
        "name": "mb",
        "precision": 6,
        "unit": "MB",
        "notation": "auto",
        "showWhen": {
          "bytePolicy": [
            "exact"
          ]
        }
      },
      {
        "name": "gb",
        "precision": 6,
        "unit": "GB",
        "notation": "auto",
        "showWhen": {
          "bytePolicy": [
            "exact"
          ]
        }
      },
      {
        "name": "tb",
        "precision": 6,
        "unit": "TB",
        "notation": "auto",
        "showWhen": {
          "bytePolicy": [
            "exact"
          ]
        }
      },
      {
        "name": "mib",
        "precision": 6,
        "unit": "MiB",
        "notation": "auto",
        "showWhen": {
          "bytePolicy": [
            "exact"
          ]
        }
      }
    ],
    "interpret": null
  }
}
