Ruby 4.1.0dev (2026-11-25 revision 0988275a9ba09081fff4e51763cf8e4929ec4427)
double.h
1/*
2 * Parsing and printing binary64 float values.
3 */
4#ifndef PRISM_INTERNAL_DOUBLE_H
5#define PRISM_INTERNAL_DOUBLE_H
6
7#include "prism/buffer.h"
9
10#include <stdbool.h>
11#include <stdint.h>
12#include <string.h>
13
14/* Return the packed binary64 representation of a double. */
15static PRISM_INLINE uint64_t
16pm_binary64_bits(double value) {
17 uint64_t bits;
18 memcpy(&bits, &value, sizeof(bits));
19 return bits;
20}
21
22/* Whether the sign bit is set, including for negative zero. */
23bool pm_double_negative_p(double value);
24
25/* Whether the value is finite. */
26bool pm_double_finite_p(double value);
27
28/*
29 * Parse a decimal float literal into the nearest double, rounding ties to even.
30 * This assumes that the format of the literal has already been validated. It
31 * may start with a plus sign, which unary plus on a numeric literal leaves in
32 * its token. Underscores between digits are skipped. Sets out_of_range when the
33 * literal is nonzero but its value rounds to zero or to infinity.
34 */
35double pm_double_parse(const uint8_t *start, const uint8_t *end, bool *out_of_range);
36
37/* Append the shortest round-tripping decimal in Ruby's Float#inspect format. */
38void pm_double_string(pm_buffer_t *buffer, double value);
39
40#endif
#define PRISM_INLINE
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition inline.h:12
A wrapper around a contiguous block of allocated memory.
C99 shim for <stdbool.h>.