Home

cospi

Cospi is a shorthand mathematical and programming term for the function defined by cospi(x) = cos(pi * x). It is used in several programming languages and mathematical libraries as a convenient way to compute the cosine of a quantity expressed in units of pi, and to help manage numerical accuracy when the input is near multiples of pi.

For real x, cospi(x) takes values in the interval [-1, 1]. It is an even function, meaning

Implementation and use vary by language. In languages such as Julia, cospi (and related sinpi) are built-in

See also: cos, sin, pi, sinpi, tanpi.

cospi(-x)
=
cospi(x).
It
has
a
period
of
2,
so
cospi(x
+
2)
=
cospi(x).
At
integer
arguments,
cospi(n)
=
cos(pi
n)
=
(-1)^n.
It
vanishes
at
half-integers,
specifically
at
x
=
k
+
1/2
for
any
integer
k.
functions
that
compute
cos(pi*x)
directly,
often
with
argument-reduction
strategies
designed
to
maintain
precision
when
x
is
near
integers
or
half-integers.
Other
languages
and
math
libraries
provide
analogous
functionality
under
the
same
or
similar
naming
conventions,
or
through
simple
definitions
as
cos(pi*x).
The
function
is
typically
used
in
numerical
analysis,
computer
graphics,
signal
processing,
and
any
domain
where
quantities
are
naturally
expressed
in
units
of
pi.