1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Make RATIONAL_SET_{NUM,DEN} static inline functions

This commit is contained in:
Kenta Murata 2020-01-17 09:05:17 +09:00
parent 8ab11096ef
commit 019a0ed0c7
No known key found for this signature in database
GPG key ID: CEFE8AFB6081B062
3 changed files with 21 additions and 7 deletions

View file

@ -11,6 +11,7 @@
*/
#include "ruby/config.h" /* for HAVE_LIBGMP */
#include "ruby/ruby.h" /* for struct RBasic */
#include "internal/gc.h" /* for RB_OBJ_WRITE */
struct RRational {
struct RBasic basic;
@ -19,8 +20,6 @@ struct RRational {
};
#define RRATIONAL(obj) (R_CAST(RRational)(obj))
#define RRATIONAL_SET_NUM(rat, n) RB_OBJ_WRITE((rat), &RRATIONAL(rat)->num, (n))
#define RRATIONAL_SET_DEN(rat, d) RB_OBJ_WRITE((rat), &RRATIONAL(rat)->den, (d))
/* rational.c */
VALUE rb_rational_canonicalize(VALUE x);
@ -37,6 +36,9 @@ VALUE rb_numeric_quo(VALUE x, VALUE y);
VALUE rb_float_numerator(VALUE x);
VALUE rb_float_denominator(VALUE x);
static inline void RATIONAL_SET_NUM(VALUE r, VALUE n);
static inline void RATIONAL_SET_DEN(VALUE r, VALUE d);
RUBY_SYMBOL_EXPORT_BEGIN
/* rational.c (export) */
VALUE rb_gcd(VALUE x, VALUE y);
@ -46,4 +48,16 @@ VALUE rb_gcd_gmp(VALUE x, VALUE y);
#endif
RUBY_SYMBOL_EXPORT_END
static inline void
RATIONAL_SET_NUM(VALUE r, VALUE n)
{
RB_OBJ_WRITE(r, &RRATIONAL(r)->num, n);
}
static inline void
RATIONAL_SET_DEN(VALUE r, VALUE d)
{
RB_OBJ_WRITE(r, &RRATIONAL(r)->den, d);
}
#endif /* INTERNAL_RATIONAL_H */