Skip to content

Commit

Permalink
Use k_exact_zero_p where appropriate in RubyComplex
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Dec 17, 2024
1 parent 369a7e7 commit ff91d1f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/RubyComplex.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,16 +497,16 @@ private static IRubyObject convertCommon(ThreadContext context, IRubyObject recv

if (a1 instanceof RubyComplex) {
RubyComplex a1c = (RubyComplex) a1;
if (k_exact_p(a1c.image) && f_zero_p(context, a1c.image)) a1 = a1c.real;
if (k_exact_zero_p(context, a1c.image)) a1 = a1c.real;
}

if (a2 instanceof RubyComplex) {
RubyComplex a2c = (RubyComplex) a2;
if (k_exact_p(a2c.image) && f_zero_p(context, a2c.image)) a2 = a2c.real;
if (k_exact_zero_p(context, a2c.image)) a2 = a2c.real;
}

if (a1 instanceof RubyComplex) {
if (singleArg || (k_exact_p(a2) && f_zero_p(context, a2))) return a1;
if (singleArg || (k_exact_zero_p(context, a2))) return a1;
}

if (singleArg) {
Expand Down Expand Up @@ -714,15 +714,15 @@ public IRubyObject fdiv(ThreadContext context, IRubyObject other) {
*/
@JRubyMethod(name = "**")
public IRubyObject op_expt(ThreadContext context, IRubyObject other) {
if (k_exact_p(other) && f_zero_p(context, other)) {
if (other instanceof RubyNumeric && k_exact_zero_p(context, other)) {
return newComplexBang(context, getMetaClass(), asFixnum(context, 1));
}

if (other instanceof RubyRational otherRational && f_one_p(context, otherRational.getDenominator())) {
other = f_numerator(context, other);
}

if (other instanceof RubyComplex otherComplex && f_zero_p(context, otherComplex.image)) {
if (other instanceof RubyComplex otherComplex && k_exact_zero_p(context, otherComplex.image)) {
other = otherComplex.real;
}

Expand Down Expand Up @@ -1239,7 +1239,7 @@ public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {
}

private void checkValidRational(ThreadContext context, String type) {
if (k_inexact_p(image) || !f_zero_p(context, image)) {
if (!k_exact_zero_p(context, image)) {
throw rangeError(context, "can't convert " + f_to_s(context, this).convertToString() + " into " + type);
}
}
Expand Down

0 comments on commit ff91d1f

Please sign in to comment.