function erf
erf(x: number): number

Error function.

Calculates the error function, which is commonly used in probability, statistics, and partial differential equations describing diffusion.

The error function is defined as:

          2     x
erf(x) = ───  ∫  e^(-t²) dt
         √π    0

This implementation approximates the error function with a maximal error of 1.2 × 10⁻⁷.

Examples

Compute the error function for a single value

import { assertEquals } from "jsr:@std/assert";

assertEquals(erf(0.5), 0.5204999077232426);

Compute the error function for a negative value

import { assertEquals } from "jsr:@std/assert";

assertEquals(erf(-1), -0.8427007877600068);

Compute the error function for zero

import { assertEquals } from "jsr:@std/assert";

assertEquals(erf(0), 0);

Compute the error function for a large positive value

import { assertEquals } from "jsr:@std/assert";

assertEquals(erf(2), 0.995322265010666);

Compute the error function for a large negative value

import { assertEquals } from "jsr:@std/assert";

assertEquals(erf(-2), -0.9953222650106659);

Parameters

x: number

A real value

Return Type

number

The value of the error function for the input x

Throws

If no arguments are provided