1 /** \noop-*-C++-*-vi:ft=cpp
3 * @author Ruby developers <ruby-core@ruby-lang.org>
4 * @copyright This file is a part of the programming language Ruby.
5 * Permission is hereby granted, to either redistribute and/or
6 * modify this file, provided that the conditions mentioned in the
7 * file COPYING are met. Consult the file for details.
8 * @warning Symbols prefixed with either `RUBY3` or `ruby3` are
9 * implementation details. Don't take them as canon. They could
10 * rapidly appear then vanish. The name (path) of this header file
11 * is also an implementation detail. Do not expect it to persist
12 * at the place it is now. Developers are free to move it anywhere
14 * @note To ruby-core: remember that this header can be possibly
15 * recursively included from extension libraries written in C++.
16 * Do not expect for instance `__VA_ARGS__` is always available.
17 * We assume C99 for ruby itself but we don't assume languages of
18 * extension libraries. They could be written in C++98.
19 * @brief Handling of integers formerly known as Fixnums.
21 #ifndef RUBY3_ARITHMETIC_FIXNUM_H
22 #define RUBY3_ARITHMETIC_FIXNUM_H
23 #include "ruby/backward/2/limits.h"
25 #define FIXABLE RB_FIXABLE
26 #define FIXNUM_MAX RUBY_FIXNUM_MAX
27 #define FIXNUM_MIN RUBY_FIXNUM_MIN
28 #define NEGFIXABLE RB_NEGFIXABLE
29 #define POSFIXABLE RB_POSFIXABLE
32 * FIXABLE can be applied to anything, from double to intmax_t. The problem is
33 * double. On a 64bit system RUBY_FIXNUM_MAX is 4,611,686,018,427,387,903,
34 * which is not representable by a double. The nearest value that a double can
35 * represent is 4,611,686,018,427,387,904, which is not fixable. The
36 * seemingly-stragne "< FIXNUM_MAX + 1" expression below is due to this.
38 #define RB_POSFIXABLE(_) ((_) < RUBY_FIXNUM_MAX + 1)
39 #define RB_NEGFIXABLE(_) ((_) >= RUBY_FIXNUM_MIN)
40 #define RB_FIXABLE(_) (RB_POSFIXABLE(_) && RB_NEGFIXABLE(_))
41 #define RUBY_FIXNUM_MAX (LONG_MAX / 2)
42 #define RUBY_FIXNUM_MIN (LONG_MIN / 2)
44 #endif /* RUBY3_ARITHMETIC_FIXNUM_H */