Ruby: missing/nan.c Source File

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

nan.c
1#include "ruby/missing.h"
2#include <assert.h>
3#include <stdlib.h>
4#include <string.h>
5
6double
7nan(const char *spec)
8{
9#if 0
10 /* FIXME: we have not yet seen any situation this is
11 * necessary. Please write a proper implementation that
12 * covers this branch. */
13 if (spec && spec[0]) {
14 double generated_nan;
15 int len = snprintf(NULL, 0, "NAN(%s)", spec);
16 char *buf = malloc(len + 1); /* +1 for NUL */
17 sprintf(buf, "NAN(%s)", spec);
18 generated_nan = strtod(buf, NULL);
19 free(buf);
20 return generated_nan;
21 }
22 else
23#endif
24 {
25 assert(!spec || !spec[0]);
26 return (double)NAN;
27 }
28}
assert.h
len
int len
Length of the buffer.
Definition io.h:8
strtod
#define strtod(s, e)
Just another name of ruby_strtod.
Definition util.h:223