Skip to content

Commit f3de9fb

Browse files
committed
feat: add specification for determining whether a sign bit is set
1 parent 0f64005 commit f3de9fb

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

spec/draft/API_specification/elementwise_functions.rst

Lines changed: 1 addition & 0 deletions
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

Lines changed: 33 additions & 0 deletions
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,38 @@ 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+
Parameters
2224+
----------
2225+
x: array
2226+
input array. Should have a real-valued floating-point data type.
2227+
2228+
Returns
2229+
-------
2230+
out: array
2231+
an array containing the evaluated result for each element in ``x``. The returned array must have a data type of ``bool``.
2232+
2233+
Notes
2234+
-----
2235+
2236+
**Special cases**
2237+
2238+
For real-valued floating-point operands,
2239+
2240+
- If ``x_i`` is ``+0``, the result is ``False``.
2241+
- If ``x_i`` is ``-0``, the result is ``True``.
2242+
- If ``x_i`` is ``+infinity``, the result is ``False``.
2243+
- If ``x_i`` is ``-infinity``, the result is ``True``.
2244+
- If ``x_i`` is a positive (i.e., greater than ``0``) finite number, the result is ``False``.
2245+
- If ``x_i`` is a negative (i.e., less than ``0``) finite number, the result is ``True``.
2246+
- If ``x_i`` is ``NaN`` and the sign bit of ``x_i`` is ``0``, the result is ``False``.
2247+
- If ``x_i`` is ``NaN`` and the sign bit of ``x_i`` is ``1``, the result is ``True``.
2248+
"""
2249+
2250+
22182251
def sin(x: array, /) -> array:
22192252
r"""
22202253
Calculates an implementation-dependent approximation to the sine for each element ``x_i`` of the input array ``x``.

0 commit comments

Comments
 (0)