{"record":{"id":"a79ad2e6114fdf44","repo":"TheAlgorithms/Python","slug":"frequency-cannot-be-negative","errorCode":null,"errorMessage":"Frequency cannot be negative","messagePattern":"Frequency cannot be negative","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"electronics/ind_reactance.py","lineNumber":53,"sourceCode":"    ValueError: Inductive reactance cannot be negative\n\n    >>> ind_reactance(0, 10e3, 50)\n    {'inductance': 0.0007957747154594767}\n\n    >>> ind_reactance(35e-3, 0, 50)\n    {'frequency': 227.36420441699332}\n\n    >>> ind_reactance(35e-6, 1e3, 0)\n    {'reactance': 0.2199114857512855}\n\n    \"\"\"\n\n    if (inductance, frequency, reactance).count(0) != 1:\n        raise ValueError(\"One and only one argument must be 0\")\n    if inductance < 0:\n        raise ValueError(\"Inductance cannot be negative\")\n    if frequency < 0:\n        raise ValueError(\"Frequency cannot be negative\")\n    if reactance < 0:\n        raise ValueError(\"Inductive reactance cannot be negative\")\n    if inductance == 0:\n        return {\"inductance\": reactance / (2 * pi * frequency)}\n    elif frequency == 0:\n        return {\"frequency\": reactance / (2 * pi * inductance)}\n    elif reactance == 0:\n        return {\"reactance\": 2 * pi * frequency * inductance}\n    else:\n        raise ValueError(\"Exactly one argument must be 0\")\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":35,"sourceCodeEnd":70,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/electronics/ind_reactance.py#L35-L70","documentation":"Thrown by ind_reactance() when the frequency argument is negative. Frequency in hertz is a non-negative quantity, so the function validates it after the one-zero sentinel check and refuses negative input before applying X_L = 2*pi*f*L.","triggerScenarios":"ind_reactance(35e-3, -1e3, 0) or ind_reactance(0, -50, 10) — any call where frequency < 0 and exactly one argument equals 0.","commonSituations":"Passing signed frequency data from FFT/dSP pipelines where negatives represent one sideband; sign flips from mixing radians/Hz conventions; spreadsheet imports mangling minus signs.","solutions":["Pass frequency in Hz as a non-negative number (e.g. 50 for 50 Hz mains).","If using signed FFT bins, take abs(bin) — reactance depends only on magnitude.","Validate frequency >= 0 before the call when values come from external data."],"exampleFix":"# before\nind_reactance(35e-3, -1e3, 0)  # ValueError: Frequency cannot be negative\n\n# after\nind_reactance(35e-3, abs(-1e3), 0)  # {'reactance': 219.9114857512855}","handlingStrategy":"validation","validationCode":"if frequency < 0:\n    raise ValueError('frequency must be >= 0')","typeGuard":"def valid_frequency(f: float) -> bool:\n    return f >= 0","tryCatchPattern":"try:\n    out = ind_reactance(l, f, x)\nexcept ValueError as exc:\n    if 'Frequency cannot be negative' in str(exc):\n        out = ind_reactance(l, abs(f), x)\n    else:\n        raise","preventionTips":["Take abs() of signed FFT bins before passing frequency.","Validate frequency >= 0 at ingest time.","Watch rad/s vs Hz conversions that introduce sign errors."],"tags":["electronics","validation","frequency","reactance","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}