halffloat.h 1.8 KB

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