From 9aa961b4589c35a92b2612778b8bae486ac25bef Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Sat, 18 May 2024 20:20:09 +0200 Subject: [PATCH] fix(jit): Implemented `%` operator for float --- src/Jit.zig | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Jit.zig b/src/Jit.zig index 968384ee..623c3ec3 100644 --- a/src/Jit.zig +++ b/src/Jit.zig @@ -2702,8 +2702,24 @@ fn generateBinary(self: *Self, node: Ast.Node.Index) Error!?m.MIR_op_t { }, .Percent => { if (left_type_def == .Float or right_type_def == .Float) { - // FIXME: mir doesn't seem to have a mod/rem for floats? - unreachable; + const f_res = m.MIR_new_reg_op( + self.ctx, + try self.REG("f_res", m.MIR_T_D), + ); + + const pdt = m.MIR_new_reg_op( + self.ctx, + try self.REG("p", m.MIR_T_D), + ); + + // quotient + self.DDIV(f_res, left, right); + // product + self.DMUL(pdt, f_res, right); + // remainder + self.DSUB(f_res, f_res, pdt); + + self.wrap(.Float, f_res, res); } else { self.MODS(res, left, right);