Skip to content

Commit

Permalink
ruby.h: rb_big_sign
Browse files Browse the repository at this point in the history
* include/ruby/ruby.h (RBIGNUM_SIGN): use a wrapper function to
  return the sign bit, instead of comparing with 0.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Nov 19, 2016
1 parent 5f03f75 commit 6839d47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions bignum.c
Expand Up @@ -6691,6 +6691,12 @@ rb_big_abs(VALUE x)
return x;
}

int
rb_big_sign(VALUE x)
{
return BIGNUM_SIGN(x);
}

size_t
rb_big_size(VALUE big)
{
Expand Down
7 changes: 4 additions & 3 deletions include/ruby/ruby.h
Expand Up @@ -1185,9 +1185,10 @@ void *rb_check_typeddata(VALUE, const rb_data_type_t *);
#define RSTRUCT_SET(st, idx, v) rb_struct_aset(st, INT2NUM(idx), (v))
#define RSTRUCT_GET(st, idx) rb_struct_aref(st, INT2NUM(idx))

#define RBIGNUM_SIGN(b) (RB_FIX2LONG(rb_big_cmp((b), RB_INT2FIX(0))) >= 0)
#define RBIGNUM_POSITIVE_P(b) (RB_FIX2LONG(rb_big_cmp((b), RB_INT2FIX(0))) >= 0)
#define RBIGNUM_NEGATIVE_P(b) (RB_FIX2LONG(rb_big_cmp((b), RB_INT2FIX(0))) < 0)
int rb_big_sign(VALUE);
#define RBIGNUM_SIGN(b) (rb_big_sign(b))
#define RBIGNUM_POSITIVE_P(b) (RBIGNUM_SIGN(b)!=0)
#define RBIGNUM_NEGATIVE_P(b) (RBIGNUM_SIGN(b)==0)

#define R_CAST(st) (struct st*)
#define RBASIC(obj) (R_CAST(RBasic)(obj))
Expand Down

0 comments on commit 6839d47

Please sign in to comment.