copysign¶
- copysign(x1: array, x2: array, /) array ¶
Composes a floating-point value with the magnitude of
x1_i
and the sign ofx2_i
for each element of the input arrayx1
.- Parameters:
x1 (array) – input array containing magnitudes. Should have a real-valued floating-point data type.
x2 (array) – input array whose sign bits are applied to the magnitudes of
x1
. Must be compatible withx1
(see Broadcasting). Should have a real-valued floating-point data type.
- Returns:
out (array) – an array containing the element-wise results. The returned array must have a floating-point data type determined by Type Promotion Rules.
Notes
Special cases
For real-valued floating-point operands, let
|x|
be the absolute value, and ifx1_i
is notNaN
,If
x2_i
is less than0
, the result is-|x1_i|
.If
x2_i
is-0
, the result is-|x1_i|
.If
x2_i
is+0
, the result is|x1_i|
.If
x2_i
is greater than0
, the result is|x1_i|
.If
x2_i
isNaN
and the sign bit ofx2_i
is1
, the result is-|x1_i|
.If
x2_i
isNaN
and the sign bit ofx2_i
is0
, the result is|x1_i|
.If
x1_i
isNaN
andx2_i
is less than0
, the result isNaN
with a sign bit of1
.If
x1_i
isNaN
andx2_i
is-0
, the result isNaN
with a sign bit of1
.If
x1_i
isNaN
andx2_i
is+0
, the result isNaN
with a sign bit of0
.If
x1_i
isNaN
andx2_i
is greater than0
, the result isNaN
with a sign bit of0
.If
x1_i
isNaN
andx2_i
isNaN
and the sign bit ofx2_i
is1
, the result isNaN
with a sign bit of1
.If
x1_i
isNaN
andx2_i
isNaN
and the sign bit ofx2_i
is0
, the result isNaN
with a sign bit of0
.
New in version 2023.12.