mruby-complex: fix division by zero

Fix a division by zero error when dividing a complex number by
`Complex(0, 0)`.

Co-authored-by: Gemini <gemini@google.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-08-16 06:56:56 +09:00
parent c3610fdab2
commit ef86757fd6
+8 -2
View File
@@ -414,9 +414,17 @@ mrb_complex_div(mrb_state *mrb, mrb_value self, mrb_value rhs)
mrb_int_zerodiv(mrb);
}
mrb_float f = mrb_as_float(mrb, rhs);
if (f == 0.0) {
mrb_int_zerodiv(mrb);
}
return complex_new(mrb, mrb_div_float(a->real, f), mrb_div_float(a->imaginary, f));
}
b = complex_ptr(mrb, rhs);
if (b->real == 0 && b->imaginary == 0) {
mrb_int_zerodiv(mrb);
}
struct float_pair ar, ai, br, bi;
struct float_pair br2, bi2;
struct float_pair div;
@@ -424,8 +432,6 @@ mrb_complex_div(mrb_state *mrb, mrb_value self, mrb_value rhs)
struct float_pair ai_br, ar_bi;
struct float_pair zr, zi;
b = complex_ptr(mrb, rhs);
/* Split floating-point components into significand and exponent */
ar.s = F(frexp)(a->real, &ar.x);
ai.s = F(frexp)(a->imaginary, &ai.x);