Python math.erfc() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Python 3.2+

Definition

math.erfc(x) returns the complementary error function 1.0 - math.erf(x), evaluated directly in Python 3.2+ so tiny upper-tail values keep full precision.

Once x passes around 6, 1.0 - math.erf(x) collapses to 0.0 due to rounding, whereas math.erfc(x) stays accurate far down into sub-epsilon probability tails.

math.erfc() is a function in Python's standard math module: import it with import math and call math.erfc(...), or import the name directly with from math import erfc.

Syntax

Import math and pass any real number.

python
import math

tail = math.erfc(x)
CallWhat it does
math.erfc(0)Returns 1.0.
math.erfc(float("inf"))Returns 0.0.
math.erfc(float("-inf"))Returns 2.0.
math.erfc(6.0)Returns approximately 2.151974e-17 (unlike 1 - erf(6)).

Use math.erfc(abs(z) / math.sqrt(2.0)) for two-tailed normal p-values and 0.5 * math.erfc(z / math.sqrt(2.0)) for one-tailed upper p-values.

Function signatures
python
math.erfc(x, /)
# added in Python 3.2; returns float 1.0 - erf(x) with full tail precision

Parameters

ParameterDescription
xRequired positional real number (int or float).

Return Value

Return ValueDescription
floatValue in [0.0, 2.0]; 0.0 for inf, 2.0 for -inf, nan for nan.

Python Examples

Example 1 — Avoid Tail Precision Loss at x = 6.0 With erfc()

Compare 1.0 - math.erf(x) (which drops to zero) against math.erfc(x).

python
import math

for x in [2.0, 4.0, 6.0]:
    naive = 1.0 - math.erf(x)
    exact = math.erfc(x)
    print(f"x={x:.0f} | 1-erf={naive:.6e} | erfc={exact:.6e}")

How It Works

  1. Rounding kills 1 - erf(6). Because erf(6.0) is closer to one than one ULP below one, subtracting from 1.0 produces exact zero.
  2. Tail digits preserved. math.erfc(6.0) evaluates the asymptotic tail directly, reporting 2.151974e-17.
  3. Scientific notation clarity. Formatting with :.6e shows both tiny scales clearly.

Example 2 — Compute Two-Tailed Normal p-Values From Z-Scores

Map z-scores of 1 through 4 standard deviations to two-tailed p-values.

python
import math

for z in [1.0, 2.0, 3.0, 4.0]:
    p_val = math.erfc(abs(z) / math.sqrt(2.0))
    print(f"z={z:.0f} -> two-tailed p={p_val:.6f}")

How It Works

  1. Direct two-tailed formula. Since two tails combine 1 - erf(|z| / sqrt(2)), math.erfc() gives the answer in one call.
  2. Threshold insight. Two standard deviations drop below 0.05 (0.045500), while four reach 0.000063.
  3. Absolute value safety. Wrapping z with abs() works for both positive and negative z-scores.

Example 3 — Verify erf(x) + erfc(x) == 1.0 and Infinity Limits

Check endpoints 0, inf, and -inf alongside the sum identity.

python
import math

print(math.erfc(0), math.erfc(float("inf")), math.erfc(float("-inf")))
total = math.erf(1.5) + math.erfc(1.5)
print(math.isclose(total, 1.0))

How It Works

  1. Range spans [0, 2]. Negative infinity approaches 1 - (-1) = 2.0, zero sits at 1.0, and positive infinity decays to 0.0.
  2. Complementary sum. Adding math.erf() and erfc at 1.5 equals 1.0 within tolerance.
  3. No domain errors. All finite and infinite real inputs succeed.

Frequently Asked Questions

Python 3.2, alongside math.erf().
For x >= 6, math.erf(x) rounds to 1.0 in float64 so 1.0 - math.erf(x) returns 0.0. math.erfc(x) stays accurate down into tiny positive values.
Between 0.0 (at +inf) and 2.0 (at -inf).
Use 0.5 * math.erfc(z / math.sqrt(2.0)).
No. All real numbers and infinities map cleanly into [0.0, 2.0].

Next: math.exp()

Return e raised to the power x as a float.

exp() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful