PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/port/isinf.c

https://github.com/bbt123/postgres
C | 77 lines | 54 code | 10 blank | 13 comment | 10 complexity | d13b9021e27e829f67c49f076cdb3afc MD5 | raw file
Possible License(s): AGPL-3.0
  1. /*-------------------------------------------------------------------------
  2. *
  3. * isinf.c
  4. *
  5. * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
  6. * Portions Copyright (c) 1994, Regents of the University of California
  7. *
  8. *
  9. * IDENTIFICATION
  10. * src/port/isinf.c
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #include "c.h"
  15. #include <float.h>
  16. #include <math.h>
  17. #if HAVE_FPCLASS /* this is _not_ HAVE_FP_CLASS, and not typo */
  18. #if HAVE_IEEEFP_H
  19. #include <ieeefp.h>
  20. #endif
  21. int
  22. isinf(double d)
  23. {
  24. fpclass_t type = fpclass(d);
  25. switch (type)
  26. {
  27. case FP_NINF:
  28. case FP_PINF:
  29. return 1;
  30. default:
  31. break;
  32. }
  33. return 0;
  34. }
  35. #else
  36. #if defined(HAVE_FP_CLASS) || defined(HAVE_FP_CLASS_D)
  37. #if HAVE_FP_CLASS_H
  38. #include <fp_class.h>
  39. #endif
  40. int
  41. isinf(x)
  42. double x;
  43. {
  44. #if HAVE_FP_CLASS
  45. int fpclass = fp_class(x);
  46. #else
  47. int fpclass = fp_class_d(x);
  48. #endif
  49. if (fpclass == FP_POS_INF)
  50. return 1;
  51. if (fpclass == FP_NEG_INF)
  52. return -1;
  53. return 0;
  54. }
  55. #elif defined(HAVE_CLASS)
  56. int
  57. isinf(double x)
  58. {
  59. int fpclass = class(x);
  60. if (fpclass == FP_PLUS_INF)
  61. return 1;
  62. if (fpclass == FP_MINUS_INF)
  63. return -1;
  64. return 0;
  65. }
  66. #endif
  67. #endif