log1p¶
- log1p(x: array, /) array ¶
Calculates an implementation-dependent approximation to
log(1+x)
, wherelog
refers to the natural (basee
) logarithm, for each elementx_i
of the input arrayx
.Note
The purpose of this function is to calculate
log(1+x)
more accurately whenx
is close to zero. Accordingly, conforming implementations should avoid implementing this function as simplylog(1+x)
. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.Note
For complex floating-point operands,
log1p(conj(x))
must equalconj(log1p(x))
.Note
By convention, the branch cut of the natural logarithm is the negative real axis \((-\infty, 0)\).
The natural logarithm is a continuous function from above the branch cut, taking into account the sign of the imaginary component.
Accordingly, for complex arguments, the function returns the natural logarithm in the range of a strip in the interval \([-\pi j, +\pi j]\) along the imaginary axis and mathematically unbounded along the real axis.
Note: branch cuts follow C99 and have provisional status (see Branch Cuts).
- Parameters:
x (array) – input array. Should have a floating-point data type.
- Returns:
out (array) – an array containing the evaluated result for each element in
x
. The returned array must have a floating-point data type determined by Type Promotion Rules.
Notes
Special cases
For real-valued floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is less than-1
, the result isNaN
.If
x_i
is-1
, the result is-infinity
.If
x_i
is-0
, the result is-0
.If
x_i
is+0
, the result is+0
.If
x_i
is+infinity
, the result is+infinity
.
For complex floating-point operands, let
a = real(x_i)
,b = imag(x_i)
, andIf
a
is-1
andb
is+0
, the result is-infinity + 0j
.If
a
is a finite number andb
is+infinity
, the result is+infinity + πj/2
.If
a
is a finite number andb
isNaN
, the result isNaN + NaN j
.If
a
is-infinity
andb
is a positive (i.e., greater than0
) finite number, the result is+infinity + πj
.If
a
is+infinity
andb
is a positive (i.e., greater than0
) finite number, the result is+infinity + 0j
.If
a
is-infinity
andb
is+infinity
, the result is+infinity + 3πj/4
.If
a
is+infinity
andb
is+infinity
, the result is+infinity + πj/4
.If
a
is either+infinity
or-infinity
andb
isNaN
, the result is+infinity + NaN j
.If
a
isNaN
andb
is a finite number, the result isNaN + NaN j
.If
a
isNaN
andb
is+infinity
, the result is+infinity + NaN j
.If
a
isNaN
andb
isNaN
, the result isNaN + NaN j
.
Changed in version 2022.12: Added complex data type support.