{"record":{"id":"cba9ba0d7825004c","repo":"TheAlgorithms/Python","slug":"math-domain-error-cba9ba","errorCode":null,"errorMessage":"math domain error","messagePattern":"math domain error","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/numerical_analysis/square_root.py","lineNumber":47,"sourceCode":"    True\n\n    >>> square_root_iterative(-1)\n    Traceback (most recent call last):\n        ...\n    ValueError: math domain error\n\n    >>> square_root_iterative(4)\n    2.0\n\n    >>> square_root_iterative(3.2)\n    1.788854381999832\n\n    >>> square_root_iterative(140)\n    11.832159566199232\n    \"\"\"\n\n    if a < 0:\n        raise ValueError(\"math domain error\")\n\n    value = get_initial_point(a)\n\n    for _ in range(max_iter):\n        prev_value = value\n        value = value - fx(value, a) / fx_derivative(value)\n        if abs(prev_value - value) < tolerance:\n            return value\n\n    return value\n\n\nif __name__ == \"__main__\":\n    from doctest import testmod\n\n    testmod()\n","sourceCodeStart":29,"sourceCodeEnd":64,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/numerical_analysis/square_root.py#L29-L64","documentation":"Error \"math domain error\" thrown in TheAlgorithms/Python.","triggerScenarios":"Thrown at maths/numerical_analysis/square_root.py:47 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-negative number to the square root function.","Use the complex variant if negative inputs are expected."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}