summaryrefslogtreecommitdiff
path: root/src/port/isinf.c
blob: 441589c027071d920f8737df6013d7ec9c5c42d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*-------------------------------------------------------------------------
 *
 * isinf.c
 *
 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  $PostgreSQL: pgsql/src/port/isinf.c,v 1.12 2008/01/01 19:46:00 momjian Exp $
 *
 *-------------------------------------------------------------------------
 */

#include "c.h"

#include <float.h>
#include <math.h>

#if HAVE_FPCLASS				/* this is _not_ HAVE_FP_CLASS, and not typo */

#if HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
int
isinf(double d)
{
	fpclass_t	type = fpclass(d);

	switch (type)
	{
		case FP_NINF:
		case FP_PINF:
			return 1;
		default:
			break;
	}
	return 0;
}
#else

#if defined(HAVE_FP_CLASS) || defined(HAVE_FP_CLASS_D)

#if HAVE_FP_CLASS_H
#include <fp_class.h>
#endif
int
isinf(x)
double		x;
{
#if HAVE_FP_CLASS
	int			fpclass = fp_class(x);
#else
	int			fpclass = fp_class_d(x);
#endif

	if (fpclass == FP_POS_INF)
		return 1;
	if (fpclass == FP_NEG_INF)
		return -1;
	return 0;
}
#elif defined(HAVE_CLASS)
int
isinf(double x)
{
	int			fpclass = class(x);

	if (fpclass == FP_PLUS_INF)
		return 1;
	if (fpclass == FP_MINUS_INF)
		return -1;
	return 0;
}
#endif

#endif