Ruby: missing/isinf.c Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

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
9 isinf(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/internal/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
37 isinf(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
config.h
Thin wrapper to ruby/config.h.
finite
int finite(double)
Definition: finite.c:6
isinf
int isinf(double n)
Definition: isinf.c:56
math.h
Internal header for Math.
memcmp
int memcmp(const void *s1, const void *s2, size_t len)
Definition: memcmp.c:7
isnan
#define isnan(x)
Definition: win32.h:346
inf
int inf(FILE *source, FILE *dest)
Definition: zpipe.c:92