Debian Codegraph @

include/ruby/internal/arithmetic/short.h

raw
1 #ifndef RBIMPL_ARITHMETIC_SHORT_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_ARITHMETIC_SHORT_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 Arithmetic conversion between C's `short` and Ruby's.
22 *
23 * Shyouhei wonders: why there is no SHORT2NUM, given there are both
24 * #USHORT2NUM and #CHR2FIX?
25 */
26 #include "ruby/internal/value.h"
27 #include "ruby/internal/dllexport.h"
28 #include "ruby/internal/special_consts.h"
29
30 #define RB_NUM2SHORT rb_num2short_inline /**< @alias{rb_num2short_inline} */
31 #define RB_NUM2USHORT rb_num2ushort /**< @alias{rb_num2ushort} */
32 #define NUM2SHORT RB_NUM2SHORT /**< @old{RB_NUM2SHORT} */
33 #define NUM2USHORT RB_NUM2USHORT /**< @old{RB_NUM2USHORT} */
34 #define USHORT2NUM RB_INT2FIX /**< @old{RB_INT2FIX} */
35 #define RB_FIX2SHORT rb_fix2short /**< @alias{rb_fix2ushort} */
36 #define FIX2SHORT RB_FIX2SHORT /**< @old{RB_FIX2SHORT} */
37
38 RBIMPL_SYMBOL_EXPORT_BEGIN()
39
40 /**
41 * Converts an instance of ::rb_cNumeric into C's `short`.
42 *
43 * @param[in] num Something numeric.
44 * @exception rb_eTypeError `num` is not a numeric.
45 * @exception rb_eRangeError `num` is out of range of `short`.
46 * @return The passed value converted into C's `short`.
47 */
48 short rb_num2short(VALUE num);
49
50 /**
51 * Converts an instance of ::rb_cNumeric into C's `unsigned short`.
52 *
53 * @param[in] num Something numeric.
54 * @exception rb_eTypeError `num` is not a numeric.
55 * @exception rb_eRangeError `num` is out of range of `unsigned short`.
56 * @return The passed value converted into C's `unsigned short`.
57 */
58 unsigned short rb_num2ushort(VALUE num);
59
60 /**
61 * Identical to rb_num2short().
62 *
63 * @param[in] num Something numeric.
64 * @exception rb_eTypeError `num` is not a numeric.
65 * @exception rb_eRangeError `num` is out of range of `short`.
66 * @return The passed value converted into C's `short`.
67 *
68 * @internal
69 *
70 * This function seems to be a complete waste of disk space. @shyouhei has no
71 * idea why this is a different thing from rb_num2short().
72 */
73 short rb_fix2short(VALUE num);
74
75 /**
76 * Identical to rb_num2ushort().
77 *
78 * @param[in] num Something numeric.
79 * @exception rb_eTypeError `num` is not a numeric.
80 * @exception rb_eRangeError `num` is out of range of `unsigned short`.
81 * @return The passed value converted into C's `unsigned short`.
82 *
83 * @internal
84 *
85 * This function seems to be a complete waste of disk space. @shyouhei has no
86 * idea why this is a different thing from rb_num2ushort().
87 */
88 unsigned short rb_fix2ushort(VALUE num);
89 RBIMPL_SYMBOL_EXPORT_END()
90
91 /**
92 * Identical to rb_num2short().
93 *
94 * @param[in] x Something numeric.
95 * @exception rb_eTypeError `x` is not a numeric.
96 * @exception rb_eRangeError `x` is out of range of `short`.
97 * @return The passed value converted into C's `short`.
98 *
99 * @internal
100 *
101 * This function seems to be a complete waste of time. @shyouhei has no idea
102 * why this is a different thing from rb_num2short().
103 */
104 static inline short
105 rb_num2short_inline(VALUE x)
106 {
107 if (RB_FIXNUM_P(x))
108 return rb_fix2short(x);
109 else
110 return rb_num2short(x);
111 }
112
113 #endif /* RBIMPL_ARITHMETIC_SHORT_H */