{"record":{"id":"d2bbe614b1dde844","repo":"TheAlgorithms/Python","slug":"area-ellipse-only-accepts-non-negative-values","errorCode":null,"errorMessage":"area_ellipse() only accepts non-negative values","messagePattern":"area_ellipse\\(\\) only accepts non-negative values","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/area.py","lineNumber":481,"sourceCode":"    >>> area_ellipse(0, 0)\r\n    0.0\r\n    >>> area_ellipse(1.6, 2.6)\r\n    13.06902543893354\r\n    >>> area_ellipse(-10, 20)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: area_ellipse() only accepts non-negative values\r\n    >>> area_ellipse(10, -20)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: area_ellipse() only accepts non-negative values\r\n    >>> area_ellipse(-10, -20)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: area_ellipse() only accepts non-negative values\r\n    \"\"\"\r\n    if radius_x < 0 or radius_y < 0:\r\n        raise ValueError(\"area_ellipse() only accepts non-negative values\")\r\n    return pi * radius_x * radius_y\r\n\r\n\r\ndef area_rhombus(diagonal_1: float, diagonal_2: float) -> float:\r\n    \"\"\"\r\n    Calculate the area of a rhombus.\r\n\r\n    >>> area_rhombus(10, 20)\r\n    100.0\r\n    >>> area_rhombus(1.6, 2.6)\r\n    2.08\r\n    >>> area_rhombus(0, 0)\r\n    0.0\r\n    >>> area_rhombus(-1, -2)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: area_rhombus() only accepts non-negative values\r\n    >>> area_rhombus(1, -2)\r","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/area.py#L463-L499","documentation":"area_ellipse() raises this ValueError when radius_x or radius_y is negative. Semi-axes are physical lengths; the library enforces >= 0 before returning pi * radius_x * radius_y. This also prevents the classic bug where two negatives multiply into a plausible-looking but wrong area.","triggerScenarios":"Calling area_ellipse(radius_x, radius_y) with either argument < 0, e.g. area_ellipse(10, -20) or area_ellipse(-10, -20).","commonSituations":"Semi-axes taken from orbital/elliptical data with signed conventions; coordinate-derived extents where a direction flips sign; imported data with negative sentinels.","solutions":["Validate both radii >= 0 before calling; fix the negative source.","Normalize signed extents to magnitudes with abs().","Clean imported datasets before computation.","Catch ValueError and report both values."],"exampleFix":"// before\narea = area_ellipse(rx, ry)  # rx = x_max - x_min style delta may be < 0\n\n# after\narea = area_ellipse(abs(rx), abs(ry))","handlingStrategy":"validation","validationCode":"if radius_x < 0 or radius_y < 0:\n    raise ValueError(f'ellipse semi-axes must be >= 0: {radius_x}, {radius_y}')\narea = area_ellipse(radius_x, radius_y)","typeGuard":"def is_valid_semi_axes(rx: float, ry: float) -> bool:\n    return rx >= 0 and ry >= 0","tryCatchPattern":"try:\n    area = area_ellipse(radius_x, radius_y)\nexcept ValueError as e:\n    raise ValueError(f'invalid ellipse input: {e}') from e","preventionTips":["Convert signed extents to magnitudes with abs() before calling.","Two negative semi-axes multiply to a positive area — the guard catches what your eye may not."],"tags":["python","math","geometry","validation","valueerror","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}