numpy 2.0.0
|
00001 #ifndef __NPY_HALFFLOAT_H__ 00002 #define __NPY_HALFFLOAT_H__ 00003 00004 #include <Python.h> 00005 #include <numpy/ndarraytypes.h> 00006 #include <numpy/npy_math.h> 00007 00008 #ifdef __cplusplus 00009 extern "C" { 00010 #endif 00011 00012 /* 00013 * Half-precision routines 00014 */ 00015 00016 /* Conversions */ 00017 float npy_half_to_float(npy_half h); 00018 double npy_half_to_double(npy_half h); 00019 npy_half npy_float_to_half(float f); 00020 npy_half npy_double_to_half(double d); 00021 /* Comparisons */ 00022 int npy_half_eq(npy_half h1, npy_half h2); 00023 int npy_half_ne(npy_half h1, npy_half h2); 00024 int npy_half_le(npy_half h1, npy_half h2); 00025 int npy_half_lt(npy_half h1, npy_half h2); 00026 int npy_half_ge(npy_half h1, npy_half h2); 00027 int npy_half_gt(npy_half h1, npy_half h2); 00028 /* faster *_nonan variants for when you know h1 and h2 are not NaN */ 00029 int npy_half_eq_nonan(npy_half h1, npy_half h2); 00030 int npy_half_lt_nonan(npy_half h1, npy_half h2); 00031 int npy_half_le_nonan(npy_half h1, npy_half h2); 00032 /* Miscellaneous functions */ 00033 int npy_half_iszero(npy_half h); 00034 int npy_half_isnan(npy_half h); 00035 int npy_half_isinf(npy_half h); 00036 int npy_half_isfinite(npy_half h); 00037 int npy_half_signbit(npy_half h); 00038 npy_half npy_half_copysign(npy_half x, npy_half y); 00039 npy_half npy_half_spacing(npy_half h); 00040 npy_half npy_half_nextafter(npy_half x, npy_half y); 00041 00042 /* 00043 * Half-precision constants 00044 */ 00045 00046 #define NPY_HALF_ZERO (0x0000u) 00047 #define NPY_HALF_PZERO (0x0000u) 00048 #define NPY_HALF_NZERO (0x8000u) 00049 #define NPY_HALF_ONE (0x3c00u) 00050 #define NPY_HALF_NEGONE (0xbc00u) 00051 #define NPY_HALF_PINF (0x7c00u) 00052 #define NPY_HALF_NINF (0xfc00u) 00053 #define NPY_HALF_NAN (0x7e00u) 00054 00055 /* 00056 * Bit-level conversions 00057 */ 00058 00059 npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f); 00060 npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d); 00061 npy_uint32 npy_halfbits_to_floatbits(npy_uint16 h); 00062 npy_uint64 npy_halfbits_to_doublebits(npy_uint16 h); 00063 00064 #ifdef __cplusplus 00065 } 00066 #endif 00067 00068 #endif