Skip to content

Commit 245bee9

Browse files
committed
DOC: __trunc__ for scalars (#27789)
1 parent 4bdc3ba commit 245bee9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Add __trunc__ method to NumPy scalar types
2+
==========================================
3+
4+
NumPy scalar floating and integer types now implement the ``__trunc__`` special method, matching Python’s built-in numeric types. This enables direct use of :func:`math.trunc` and the ``__trunc__`` dunder method on NumPy scalars:
5+
6+
Examples
7+
--------
8+
9+
.. code-block:: python
10+
11+
>>> import numpy as np
12+
>>> import math
13+
>>> math.trunc(np.float16(np.pi))
14+
3
15+
>>> np.float16(-np.pi).__trunc__()
16+
-3
17+
>>> np.int32(42).__trunc__()
18+
42
19+
20+
Attempting to truncate infinite or NaN values for floating point types will now raise the same errors as Python floats.
21+
22+
.. versionadded:: 2.3

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy