{
  "openapi": "3.1.1",
  "info": {
    "title": "Floating-Point Explorer API",
    "version": "1.0.0",
    "summary": "See how IEEE-754 half/single/double store a number: bits, exact value, ULP, rounding error.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://floatingpointexplorer.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "See how IEEE-754 half/single/double store a number: bits, exact value, ULP, rounding error.",
        "description": "Shows the sign, exponent and fraction bits of a decimal number in IEEE-754 binary16, binary32 or binary64, the exact decimal value that is actually stored (computed with big integers), the rounding error, the ULP and the neighbouring representable numbers. Evaluates expressions such as 0.1 + 0.2 step by step and explains subnormals, infinities and NaN.\n\nMethodology:\n- Decimal input is parsed as an exact fraction and rounded to the nearest representable value of the chosen format (round half to even), with big-integer arithmetic, so there is no double rounding via JavaScript numbers.\n- A normal number is (−1)^sign × 1.fraction × 2^(exponent − bias); subnormals (exponent field 0) are (−1)^sign × 0.fraction × 2^(1 − bias). The exact decimal of the stored value always terminates because the denominator is a power of two.\n- ULP is the gap to the next representable number away from zero; the neighbours are the bit patterns ±1 (crossing between ±0 and the smallest subnormals).\n- Expressions are evaluated twice: exactly with fractions, and in the chosen format with rounding after every literal and every operation (IEEE-754 semantics, like JavaScript for binary64 or C float for binary32).",
        "tags": [
          "math"
        ],
        "x-mcp-tool": "floating_point_explorer",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FloatingPointExplorerInput"
              },
              "examples": {
                "example1": {
                  "summary": "0.1 as a double",
                  "value": {
                    "value": "0.1",
                    "format": "binary64"
                  }
                },
                "example2": {
                  "summary": "0.1 + 0.2 ≠ 0.3",
                  "value": {
                    "value": "0.1 + 0.2",
                    "format": "binary64"
                  }
                },
                "example3": {
                  "summary": "Smallest half-precision subnormal",
                  "value": {
                    "value": "0x0001",
                    "format": "binary16"
                  }
                },
                "example4": {
                  "summary": "16777217 as a float",
                  "value": {
                    "value": "16777217",
                    "format": "binary32"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FloatingPointExplorerResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "FloatingPointExplorerInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "value": {
            "title": "Number, expression or bit pattern",
            "description": "A decimal (0.1, -6.02e23), an expression with + − * / and parentheses, NaN / Infinity, or a bit pattern 0x… / 0b….",
            "type": "string",
            "maxLength": 500,
            "default": "0.1"
          },
          "format": {
            "title": "Format",
            "type": "string",
            "enum": [
              "binary64",
              "binary32",
              "binary16"
            ],
            "default": "binary64"
          }
        },
        "required": [
          "value"
        ]
      },
      "FloatingPointExplorerResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "required": [
              "format",
              "input",
              "mode",
              "bits",
              "hex",
              "sign",
              "exponentField",
              "fractionField",
              "kind",
              "storedExact",
              "shortest",
              "neighbours",
              "otherFormats"
            ],
            "properties": {
              "format": {
                "type": "string"
              },
              "input": {
                "type": "string"
              },
              "mode": {
                "type": "string",
                "enum": [
                  "decimal",
                  "special",
                  "bits",
                  "expression"
                ]
              },
              "bits": {
                "type": "string",
                "description": "Binary, most significant bit first."
              },
              "hex": {
                "type": "string"
              },
              "sign": {
                "type": "integer"
              },
              "exponentField": {
                "type": "integer"
              },
              "unbiasedExponent": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "fractionField": {
                "type": "string",
                "description": "Fraction field as an integer (decimal string)."
              },
              "kind": {
                "type": "string",
                "enum": [
                  "zero",
                  "subnormal",
                  "normal",
                  "infinity",
                  "nan"
                ]
              },
              "storedExact": {
                "type": "string",
                "description": "Exact decimal value of the stored number."
              },
              "shortest": {
                "type": "string",
                "description": "Shortest decimal that rounds back to the same bits."
              },
              "roundingError": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "stored − input, exact decimal (null if not applicable)."
              },
              "relativeError": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "ulp": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Distance to the next number away from zero (exact decimal)."
              },
              "neighbours": {
                "type": "object",
                "required": [
                  "previous",
                  "next"
                ],
                "properties": {
                  "previous": {
                    "type": "string"
                  },
                  "next": {
                    "type": "string"
                  }
                }
              },
              "expression": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "exact": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "result": {
                    "type": "string"
                  },
                  "correctlyRounded": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "equalsCorrectlyRounded": {
                    "type": [
                      "boolean",
                      "null"
                    ]
                  },
                  "steps": {
                    "type": "array"
                  }
                }
              },
              "otherFormats": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "format",
                    "hex",
                    "stored"
                  ],
                  "properties": {
                    "format": {
                      "type": "string"
                    },
                    "hex": {
                      "type": "string"
                    },
                    "stored": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}