1 /*-------------------------------------------------------------------------
2  *
3  * isinf.c
4  *
5  * Portions Copyright (c) 1996-2017, 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 
15 #include "c.h"
16 
17 #include <float.h>
18 #include <math.h>
19 
20 #if HAVE_FPCLASS				/* this is _not_ HAVE_FP_CLASS, and not typo */
21 
22 #if HAVE_IEEEFP_H
23 #include <ieeefp.h>
24 #endif
25 int
isinf(double d)26 isinf(double d)
27 {
28 	fpclass_t	type = fpclass(d);
29 
30 	switch (type)
31 	{
32 		case FP_NINF:
33 		case FP_PINF:
34 			return 1;
35 		default:
36 			break;
37 	}
38 	return 0;
39 }
40 #else
41 
42 #if defined(HAVE_FP_CLASS) || defined(HAVE_FP_CLASS_D)
43 
44 #if HAVE_FP_CLASS_H
45 #include <fp_class.h>
46 #endif
47 int
isinf(x)48 isinf(x)
49 double		x;
50 {
51 #if HAVE_FP_CLASS
52 	int			fpclass = fp_class(x);
53 #else
54 	int			fpclass = fp_class_d(x);
55 #endif
56 
57 	if (fpclass == FP_POS_INF)
58 		return 1;
59 	if (fpclass == FP_NEG_INF)
60 		return -1;
61 	return 0;
62 }
63 #elif defined(HAVE_CLASS)
64 int
isinf(double x)65 isinf(double x)
66 {
67 	int			fpclass = class(x);
68 
69 	if (fpclass == FP_PLUS_INF)
70 		return 1;
71 	if (fpclass == FP_MINUS_INF)
72 		return -1;
73 	return 0;
74 }
75 #endif
76 
77 #endif
78