Debian Codegraph @

include/ruby/internal/arithmetic/fixnum.h

raw
1 #ifndef RBIMPL_ARITHMETIC_FIXNUM_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_ARITHMETIC_FIXNUM_H
3 /**
4 * @file
5 * @author Ruby developers <[email protected]>
6 * @copyright This file is a part of the programming language Ruby.
7 * Permission is hereby granted, to either redistribute and/or
8 * modify this file, provided that the conditions mentioned in the
9 * file COPYING are met. Consult the file for details.
10 * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11 * implementation details. Don't take them as canon. They could
12 * rapidly appear then vanish. The name (path) of this header file
13 * is also an implementation detail. Do not expect it to persist
14 * at the place it is now. Developers are free to move it anywhere
15 * anytime at will.
16 * @note To ruby-core: remember that this header can be possibly
17 * recursively included from extension libraries written in C++.
18 * Do not expect for instance `__VA_ARGS__` is always available.
19 * We assume C99 for ruby itself but we don't assume languages of
20 * extension libraries. They could be written in C++98.
21 * @brief Handling of integers formerly known as Fixnums.
22 */
23 #include "ruby/backward/2/limits.h"
24
25 #define FIXABLE RB_FIXABLE /**< @old{RB_FIXABLE} */
26 #define FIXNUM_MAX RUBY_FIXNUM_MAX /**< @old{RUBY_FIXNUM_MAX} */
27 #define FIXNUM_MIN RUBY_FIXNUM_MIN /**< @old{RUBY_FIXNUM_MIN} */
28 #define NEGFIXABLE RB_NEGFIXABLE /**< @old{RB_NEGFIXABLE} */
29 #define POSFIXABLE RB_POSFIXABLE /**< @old{RB_POSFIXABLE} */
30
31 /**
32 * Checks if the passed value is in range of fixnum, assuming it is a positive
33 * number. Can sometimes be useful for C's unsigned integer types.
34 *
35 * @internal
36 *
37 * FIXABLE can be applied to anything, from double to intmax_t. The problem is
38 * double. On a 64bit system RUBY_FIXNUM_MAX is 4,611,686,018,427,387,903,
39 * which is not representable by a double. The nearest value that a double can
40 * represent is 4,611,686,018,427,387,904, which is not fixable. The
41 * seemingly-strange "< FIXNUM_MAX + 1" expression below is due to this.
42 */
43 #define RB_POSFIXABLE(_) ((_) < RUBY_FIXNUM_MAX + 1)
44
45 /**
46 * Checks if the passed value is in range of fixnum, assuming it is a negative
47 * number. This is an implementation of #RB_FIXABLE. Rarely used stand alone.
48 */
49 #define RB_NEGFIXABLE(_) ((_) >= RUBY_FIXNUM_MIN)
50
51 /** Checks if the passed value is in range of fixnum */
52 #define RB_FIXABLE(_) (RB_POSFIXABLE(_) && RB_NEGFIXABLE(_))
53
54 /** Maximum possible value that a fixnum can represent. */
55 #define RUBY_FIXNUM_MAX (LONG_MAX / 2)
56
57 /** Minimum possible value that a fixnum can represent. */
58 #define RUBY_FIXNUM_MIN (LONG_MIN / 2)
59
60 #endif /* RBIMPL_ARITHMETIC_FIXNUM_H */