numpy
2.0.0
|
00001 #ifndef __NPY_HALFFLOAT_H__ 00002 #define __NPY_HALFFLOAT_H__ 00003 00004 #include <Python.h> 00005 #include <numpy/npy_math.h> 00006 00007 #ifdef __cplusplus 00008 extern "C" { 00009 #endif 00010 00011 /* 00012 * Half-precision routines 00013 */ 00014 00015 /* Conversions */ 00016 float npy_half_to_float(npy_half h); 00017 double npy_half_to_double(npy_half h); 00018 npy_half npy_float_to_half(float f); 00019 npy_half npy_double_to_half(double d); 00020 /* Comparisons */ 00021 int npy_half_eq(npy_half h1, npy_half h2); 00022 int npy_half_ne(npy_half h1, npy_half h2); 00023 int npy_half_le(npy_half h1, npy_half h2); 00024 int npy_half_lt(npy_half h1, npy_half h2); 00025 int npy_half_ge(npy_half h1, npy_half h2); 00026 int npy_half_gt(npy_half h1, npy_half h2); 00027 /* faster *_nonan variants for when you know h1 and h2 are not NaN */ 00028 int npy_half_eq_nonan(npy_half h1, npy_half h2); 00029 int npy_half_lt_nonan(npy_half h1, npy_half h2); 00030 int npy_half_le_nonan(npy_half h1, npy_half h2); 00031 /* Miscellaneous functions */ 00032 int npy_half_iszero(npy_half h); 00033 int npy_half_isnan(npy_half h); 00034 int npy_half_isinf(npy_half h); 00035 int npy_half_isfinite(npy_half h); 00036 int npy_half_signbit(npy_half h); 00037 npy_half npy_half_copysign(npy_half x, npy_half y); 00038 npy_half npy_half_spacing(npy_half h); 00039 npy_half npy_half_nextafter(npy_half x, npy_half y); 00040 npy_half npy_half_divmod(npy_half x, npy_half y, npy_half *modulus); 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 #define NPY_MAX_HALF (0x7bffu) 00056 00057 /* 00058 * Bit-level conversions 00059 */ 00060 00061 npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f); 00062 npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d); 00063 npy_uint32 npy_halfbits_to_floatbits(npy_uint16 h); 00064 npy_uint64 npy_halfbits_to_doublebits(npy_uint16 h); 00065 00066 #ifdef __cplusplus 00067 } 00068 #endif 00069 00070 #endif