Header And Logo

PostgreSQL
| The world's most advanced open source database.

isinf.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * isinf.c
00004  *
00005  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00006  * Portions Copyright (c) 1994, Regents of the University of California
00007  *
00008  *
00009  * IDENTIFICATION
00010  *    src/port/isinf.c
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 
00015 #include "c.h"
00016 
00017 #include <float.h>
00018 #include <math.h>
00019 
00020 #if HAVE_FPCLASS                /* this is _not_ HAVE_FP_CLASS, and not typo */
00021 
00022 #if HAVE_IEEEFP_H
00023 #include <ieeefp.h>
00024 #endif
00025 int
00026 isinf(double d)
00027 {
00028     fpclass_t   type = fpclass(d);
00029 
00030     switch (type)
00031     {
00032         case FP_NINF:
00033         case FP_PINF:
00034             return 1;
00035         default:
00036             break;
00037     }
00038     return 0;
00039 }
00040 #else
00041 
00042 #if defined(HAVE_FP_CLASS) || defined(HAVE_FP_CLASS_D)
00043 
00044 #if HAVE_FP_CLASS_H
00045 #include <fp_class.h>
00046 #endif
00047 int
00048 isinf(x)
00049 double      x;
00050 {
00051 #if HAVE_FP_CLASS
00052     int         fpclass = fp_class(x);
00053 #else
00054     int         fpclass = fp_class_d(x);
00055 #endif
00056 
00057     if (fpclass == FP_POS_INF)
00058         return 1;
00059     if (fpclass == FP_NEG_INF)
00060         return -1;
00061     return 0;
00062 }
00063 #elif defined(HAVE_CLASS)
00064 int
00065 isinf(double x)
00066 {
00067     int         fpclass = class(x);
00068 
00069     if (fpclass == FP_PLUS_INF)
00070         return 1;
00071     if (fpclass == FP_MINUS_INF)
00072         return -1;
00073     return 0;
00074 }
00075 #endif
00076 
00077 #endif