Skip to content

Commit 5a14534

Browse files
authored
Add signbit specification for determining whether a sign bit is set (data-apis#705)
1 parent f5d8304 commit 5a14534

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

spec/draft/API_specification/elementwise_functions.rst

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Objects in API
6969
remainder
7070
round
7171
sign
72+
signbit
7273
sin
7374
sinh
7475
square

src/array_api_stubs/_draft/elementwise_functions.py

+35
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"remainder",
5252
"round",
5353
"sign",
54+
"signbit",
5455
"sin",
5556
"sinh",
5657
"square",
@@ -2215,6 +2216,40 @@ def sign(x: array, /) -> array:
22152216
"""
22162217

22172218

2219+
def signbit(x: array, /) -> array:
2220+
r"""
2221+
Determines whether the sign bit is set for each element ``x_i`` of the input array ``x``.
2222+
2223+
The sign bit of a real-valued floating-point number ``x_i`` is set whenever ``x_i`` is either ``-0``, less than zero, or a signed ``NaN`` (i.e., a ``NaN`` value whose sign bit is ``1``).
2224+
2225+
Parameters
2226+
----------
2227+
x: array
2228+
input array. Should have a real-valued floating-point data type.
2229+
2230+
Returns
2231+
-------
2232+
out: array
2233+
an array containing the evaluated result for each element in ``x``. The returned array must have a data type of ``bool``.
2234+
2235+
Notes
2236+
-----
2237+
2238+
**Special cases**
2239+
2240+
For real-valued floating-point operands,
2241+
2242+
- If ``x_i`` is ``+0``, the result is ``False``.
2243+
- If ``x_i`` is ``-0``, the result is ``True``.
2244+
- If ``x_i`` is ``+infinity``, the result is ``False``.
2245+
- If ``x_i`` is ``-infinity``, the result is ``True``.
2246+
- If ``x_i`` is a positive (i.e., greater than ``0``) finite number, the result is ``False``.
2247+
- If ``x_i`` is a negative (i.e., less than ``0``) finite number, the result is ``True``.
2248+
- If ``x_i`` is ``NaN`` and the sign bit of ``x_i`` is ``0``, the result is ``False``.
2249+
- If ``x_i`` is ``NaN`` and the sign bit of ``x_i`` is ``1``, the result is ``True``.
2250+
"""
2251+
2252+
22182253
def sin(x: array, /) -> array:
22192254
r"""
22202255
Calculates an implementation-dependent approximation to the sine for each element ``x_i`` of the input array ``x``.

0 commit comments

Comments
 (0)