Skip to content

Commit

Permalink
Boilerplate code for rb_absint_size()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yorick Peterse committed May 8, 2015
1 parent fb79894 commit 6b132e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions vm/capi/bignum.cpp
Expand Up @@ -164,4 +164,19 @@ extern "C" {
INTEGER_PACK_LSWORD_FIRST | INTEGER_PACK_NATIVE_BYTE_ORDER |
INTEGER_PACK_2COMP);
}

size_t rb_absint_size(VALUE val, int *nlz_bits_ret)
{
VALUE abs = capi_fast_call(val, rb_intern("abs"), 0);
size_t size;

if(FIXNUM_P(abs)) {
size = 0;
// Bignum
} else {
size = rb_big_bytes_used(abs);
}

return size;
}
}
3 changes: 3 additions & 0 deletions vm/include/capi/ruby/ruby.h
Expand Up @@ -1106,6 +1106,9 @@ struct RTypedData {
void rb_big_pack(VALUE val, unsigned long *buf, long num_longs);

int rb_big_sign(VALUE obj);

size_t rb_absint_size(VALUE val, int *nlz_bits_ret);

#define RBIGNUM_SIGN(obj) rb_big_sign(obj)
#define RBIGNUM_POSITIVE_P(b) RBIGNUM_SIGN(b)
#define RBIGNUM_NEGATIVE_P(b) (!RBIGNUM_SIGN(b))
Expand Down

0 comments on commit 6b132e1

Please sign in to comment.