Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
halffloat.h71 linesDownload Raw Back to numpy
1#ifndef NUMPY_CORE_INCLUDE_NUMPY_HALFFLOAT_H_
2#define NUMPY_CORE_INCLUDE_NUMPY_HALFFLOAT_H_
3
4#include <Python.h>
5#include <numpy/npy_math.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11/*
12 * Half-precision routines
13 */
14
15/* Conversions */
16float npy_half_to_float(npy_half h);
17double npy_half_to_double(npy_half h);
18npy_half npy_float_to_half(float f);
19npy_half npy_double_to_half(double d);
20/* Comparisons */
21int npy_half_eq(npy_half h1, npy_half h2);
22int npy_half_ne(npy_half h1, npy_half h2);
23int npy_half_le(npy_half h1, npy_half h2);
24int npy_half_lt(npy_half h1, npy_half h2);
25int npy_half_ge(npy_half h1, npy_half h2);
26int npy_half_gt(npy_half h1, npy_half h2);
27/* faster *_nonan variants for when you know h1 and h2 are not NaN */
28int npy_half_eq_nonan(npy_half h1, npy_half h2);
29int npy_half_lt_nonan(npy_half h1, npy_half h2);
30int npy_half_le_nonan(npy_half h1, npy_half h2);
31/* Miscellaneous functions */
32int npy_half_iszero(npy_half h);
33int npy_half_isnan(npy_half h);
34int npy_half_isinf(npy_half h);
35int npy_half_isfinite(npy_half h);
36int npy_half_signbit(npy_half h);
37npy_half npy_half_copysign(npy_half x, npy_half y);
38npy_half npy_half_spacing(npy_half h);
39npy_half npy_half_nextafter(npy_half x, npy_half y);
40npy_half npy_half_divmod(npy_half x, npy_half y, npy_half *modulus);
41
42/*
43 * Half-precision constants
44 */
45
46#define NPY_HALF_ZERO   (0x0000u)
47#define NPY_HALF_PZERO  (0x0000u)
48#define NPY_HALF_NZERO  (0x8000u)
49#define NPY_HALF_ONE    (0x3c00u)
50#define NPY_HALF_NEGONE (0xbc00u)
51#define NPY_HALF_PINF   (0x7c00u)
52#define NPY_HALF_NINF   (0xfc00u)
53#define NPY_HALF_NAN    (0x7e00u)
54
55#define NPY_MAX_HALF    (0x7bffu)
56
57/*
58 * Bit-level conversions
59 */
60
61npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f);
62npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d);
63npy_uint32 npy_halfbits_to_floatbits(npy_uint16 h);
64npy_uint64 npy_halfbits_to_doublebits(npy_uint16 h);
65
66#ifdef __cplusplus
67}
68#endif
69
70#endif  /* NUMPY_CORE_INCLUDE_NUMPY_HALFFLOAT_H_ */
71 
codekingpro/portable-devtools · Team Ai