Skip to content

Commit bf95f56

Browse files
committedFeb 23, 2018
Merge branch 'master' into ruby-2.5
2 parents c4afc88 + e8ef793 commit bf95f56

File tree

6 files changed

+45
-43
lines changed

6 files changed

+45
-43
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/RubyFixnum.java

-16
Original file line numberDiff line numberDiff line change
@@ -1379,22 +1379,6 @@ public RubyRational convertToRational() {
13791379
return RubyRational.newRationalRaw(runtime, this, one(runtime));
13801380
}
13811381

1382-
@Override
1383-
public IRubyObject remainder(ThreadContext context, IRubyObject y) {
1384-
RubyFixnum x = this;
1385-
JavaSites.FixnumSites sites = sites(context);
1386-
IRubyObject z = sites.op_mod.call(context, this, this, y);
1387-
1388-
if ((!Helpers.rbEqual(context, z, RubyFixnum.zero(context.runtime), sites.op_equal).isTrue()) &&
1389-
((x.isNegative() &&
1390-
((RubyInteger) y).isPositive()) ||
1391-
(x.isPositive() &&
1392-
((RubyInteger) y).isNegative()))) {
1393-
return sites.op_minus.call(context, z, z, y);
1394-
}
1395-
return z;
1396-
}
1397-
13981382
private static JavaSites.FixnumSites sites(ThreadContext context) {
13991383
return context.sites.Fixnum;
14001384
}

Diff for: ‎core/src/main/java/org/jruby/RubyFloat.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,23 @@ public int signum() {
200200
@Override
201201
@JRubyMethod(name = "negative?")
202202
public IRubyObject isNegative(ThreadContext context) {
203-
return context.runtime.newBoolean(signum() < 0);
203+
return context.runtime.newBoolean(isNegative());
204204
}
205205

206206
@Override
207207
@JRubyMethod(name = "positive?")
208208
public IRubyObject isPositive(ThreadContext context) {
209-
return context.runtime.newBoolean(signum() > 0);
209+
return context.runtime.newBoolean(isPositive());
210+
}
211+
212+
@Override
213+
public boolean isNegative() {
214+
return signum() < 0;
215+
}
216+
217+
@Override
218+
public boolean isPositive() {
219+
return signum() > 0;
210220
}
211221

212222
public static RubyFloat newFloat(Ruby runtime, double value) {

Diff for: ‎core/src/main/java/org/jruby/RubyInteger.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ public IRubyObject isPositive(ThreadContext context) {
123123
return context.runtime.newBoolean(isPositive());
124124
}
125125

126-
// @Override // NOTE: could be public + defined on Numeric
127-
final boolean isNegative() {
126+
@Override
127+
public boolean isNegative() {
128128
return signum() < 0;
129129
}
130130

131-
// @Override // NOTE: could be public + defined on Numeric
132-
final boolean isPositive() {
131+
@Override
132+
public boolean isPositive() {
133133
return signum() > 0;
134134
}
135135

Diff for: ‎core/src/main/java/org/jruby/RubyNumeric.java

+18-20
Original file line numberDiff line numberDiff line change
@@ -787,16 +787,20 @@ public IRubyObject modulo(ThreadContext context, IRubyObject other) {
787787
*
788788
*/
789789
@JRubyMethod(name = "remainder")
790-
public IRubyObject remainder(ThreadContext context, IRubyObject dividend) {
791-
IRubyObject z = numFuncall(context, this, sites(context).op_mod, dividend);
792-
RubyFixnum zero = RubyFixnum.zero(context.runtime);
790+
public IRubyObject remainder(ThreadContext context, IRubyObject y) {
791+
RubyNumeric x = this;
792+
JavaSites.NumericSites sites = sites(context);
793+
IRubyObject z = sites.op_mod.call(context, this, this, y);
794+
795+
// non-numeric would error out in % call
796+
RubyNumeric yNum = (RubyNumeric) y;
793797

794-
if (!equalInternal(context, z, zero) &&
795-
((isNegative(context).isTrue() &&
796-
positiveIntP(context, dividend).isTrue()) ||
797-
(isPositive(context).isTrue() &&
798-
negativeIntP(context, dividend).isTrue()))) {
799-
return sites(context).op_minus.call(context, z, z, dividend);
798+
if ((!Helpers.rbEqual(context, z, RubyFixnum.zero(context.runtime), sites.op_equal).isTrue()) &&
799+
((x.isNegative() &&
800+
yNum.isPositive()) ||
801+
(x.isPositive() &&
802+
yNum.isNegative()))) {
803+
return sites.op_minus.call(context, z, z, y);
800804
}
801805
return z;
802806
}
@@ -1342,8 +1346,8 @@ public Throwable fillInStackTrace() {
13421346
@JRubyMethod(name = "negative?")
13431347
public IRubyObject isNegative(ThreadContext context) {
13441348
return compareWithZero(context, this, sites(context).op_lt_checked);
1345-
13461349
}
1350+
13471351
/** num_positive_p
13481352
*
13491353
*/
@@ -1352,18 +1356,12 @@ public IRubyObject isPositive(ThreadContext context) {
13521356
return compareWithZero(context, this, sites(context).op_gt_checked);
13531357
}
13541358

1355-
protected static IRubyObject negativeIntP(ThreadContext context, IRubyObject obj) {
1356-
if (obj instanceof RubyNumeric) {
1357-
return ((RubyNumeric) obj).isNegative(context);
1358-
}
1359-
return compareWithZero(context, obj, sites(context).op_lt_checked);
1359+
public boolean isNegative() {
1360+
return isNegative(getRuntime().getCurrentContext()).isTrue();
13601361
}
13611362

1362-
protected static IRubyObject positiveIntP(ThreadContext context, IRubyObject obj) {
1363-
if (obj instanceof RubyNumeric) {
1364-
return ((RubyNumeric) obj).isPositive(context);
1365-
}
1366-
return compareWithZero(context, obj, sites(context).op_gt_checked);
1363+
public boolean isPositive() {
1364+
return isPositive(getRuntime().getCurrentContext()).isTrue();
13671365
}
13681366

13691367
protected static IRubyObject compareWithZero(ThreadContext context, IRubyObject num, JavaSites.CheckedSites site) {

Diff for: ‎core/src/main/java/org/jruby/RubyRational.java

+10
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,16 @@ public IRubyObject isPositive(ThreadContext context) {
471471
return context.runtime.newBoolean(signum() > 0);
472472
}
473473

474+
@Override
475+
public boolean isNegative() {
476+
return signum() < 0;
477+
}
478+
479+
@Override
480+
public boolean isPositive() {
481+
return signum() > 0;
482+
}
483+
474484
public final int signum() { return num.signum(); }
475485

476486
/** f_imul

Diff for: ‎core/src/main/java/org/jruby/runtime/JavaSites.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public static class NumericSites {
198198
public final CallSite op_rshift = new FunctionalCachingCallSite(">>");
199199
public final CallSite size = new FunctionalCachingCallSite("size");
200200
public final CallSite ceil = new FunctionalCachingCallSite("ceil");
201+
public final CallSite op_equal = new FunctionalCachingCallSite("==");
201202
}
202203

203204
public static class IntegerSites {
@@ -236,7 +237,6 @@ public static class FixnumSites {
236237
public final CheckedSites checked_op_and = new CheckedSites("&");
237238
public final CheckedSites checked_op_or = new CheckedSites("|");
238239
public final CheckedSites checked_op_xor = new CheckedSites("^");
239-
public final CallSite op_equal = new FunctionalCachingCallSite("==");
240240
}
241241

242242
public static class BignumSites {

0 commit comments

Comments
 (0)
Please sign in to comment.