Ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
isinf.c
Go to the documentation of this file.
1/* public domain rewrite of isinf(3) */
2
3#ifdef __osf__
4
5#define _IEEE 1
6#include <nan.h>
7
8int
9isinf(double n)
10{
11 if (IsNANorINF(n) && IsINF(n)) {
12 return 1;
13 }
14 else {
15 return 0;
16 }
17}
18
19#else
20
21#include "ruby/config.h"
22
23#if defined(HAVE_FINITE) && defined(HAVE_ISNAN)
24
25#include <math.h>
26#ifdef HAVE_IEEEFP_H
27#include <ieeefp.h>
28#endif
29
30/*
31 * isinf may be provided only as a macro.
32 * ex. HP-UX, Solaris 10
33 * http://www.gnu.org/software/automake/manual/autoconf/Function-Portability.html
34 */
35#ifndef isinf
36int
37isinf(double n)
38{
39 return (!finite(n) && !isnan(n));
40}
41#endif
42
43#else
44
45#ifdef HAVE_STRING_H
46# include <string.h>
47#else
48# include <strings.h>
49#endif
50
51static double zero(void) { return 0.0; }
52static double one (void) { return 1.0; }
53static double inf (void) { return one() / zero(); }
54
55int
56isinf(double n)
57{
58 static double pinf = 0.0;
59 static double ninf = 0.0;
60
61 if (pinf == 0.0) {
62 pinf = inf();
63 ninf = -pinf;
64 }
65 return memcmp(&n, &pinf, sizeof n) == 0
66 || memcmp(&n, &ninf, sizeof n) == 0;
67}
68#endif
69#endif
int isinf(double n)
Definition: isinf.c:56
int memcmp(const void *, const void *, size_t)
Definition: memcmp.c:7
const char size_t n
#define isnan(__x)
int finite(double)
Definition: finite.c:6