8000 complex.c: optimize zero check for Float · github/ruby@fc9e030 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc9e030

Browse files
committed
complex.c: optimize zero check for Float
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent f7c0abe commit fc9e030

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

complex.c

Lines changed: 4 additions & 1 deletion
< 8000 td data-grid-cell-id="diff-22d2cb438cf6d522df9f6518096ec5bffb4f7b61d8e3a3bd163a2b09285c7873-233-233-2" data-line-anchor="diff-22d2cb438cf6d522df9f6518096ec5bffb4f7b61d8e3a3bd163a2b09285c7873R233" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">
f_zero_p(VALUE x)
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ f_negative_p(VALUE x)
232232
inline static int
233233
234234
{
235-
if (RB_INTEGER_TYPE_P(x)) {
235+
if (RB_FLOAT_TYPE_P(x)) {
236+
return FLOAT_ZERO_P(x);
237+
}
238+
else if (RB_INTEGER_TYPE_P(x)) {
236239
return FIXNUM_ZERO_P(x);
237240
}
238241
else if (RB_TYPE_P(x, T_RATIONAL)) {

internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,8 @@ void Init_newline(void);
16171617

16181618
#define INT_NEGATIVE_P(x) (FIXNUM_P(x) ? FIXNUM_NEGATIVE_P(x) : BIGNUM_NEGATIVE_P(x))
16191619

1620+
#define FLOAT_ZERO_P(x) (RFLOAT_VALUE(x) == 0.0)
1621+
16201622
#ifndef ROUND_DEFAULT
16211623
# define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_UP
16221624
#endif

numeric.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ rb_float_mul(VALUE x, VALUE y)
10861086
static bool
10871087
flo_iszero(VALUE f)
10881088
{
1089-
return RFLOAT_VALUE(f) == 0.0;
1089+
return FLOAT_ZERO_P(f);
10901090
}
10911091

10921092
static double

0 commit comments

Comments
 (0)
0