]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Use fmod/fmodf for modulo operation between floating point values
authorLuca Bruno <lethalman88@gmail.com>
Thu, 11 Mar 2010 11:10:03 +0000 (12:10 +0100)
committerJürg Billeter <j@bitron.ch>
Fri, 19 Mar 2010 17:27:21 +0000 (18:27 +0100)
Fixes bug 610660.

codegen/valaccodebasemodule.vala

index fe9d70e0c21c11dd677b147b39c37ce77e7ae0c2..c7c6f81ec536cdbe9172c5ced403e12e543735af 100644 (file)
@@ -4415,7 +4415,23 @@ internal class Vala.CCodeBaseModule : CCodeModule {
                } else if (expr.operator == BinaryOperator.DIV) {
                        op = CCodeBinaryOperator.DIV;
                } else if (expr.operator == BinaryOperator.MOD) {
-                       op = CCodeBinaryOperator.MOD;
+                       if (expr.value_type.equals (double_type)) {
+                               source_declarations.add_include ("math.h");
+                               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("fmod"));
+                               ccall.add_argument (cleft);
+                               ccall.add_argument (cright);
+                               expr.ccodenode = ccall;
+                               return;
+                       } else if (expr.value_type.equals (float_type)) {
+                               source_declarations.add_include ("math.h");
+                               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("fmodf"));
+                               ccall.add_argument (cleft);
+                               ccall.add_argument (cright);
+                               expr.ccodenode = ccall;
+                               return;
+                       } else {
+                               op = CCodeBinaryOperator.MOD;
+                       }
                } else if (expr.operator == BinaryOperator.SHIFT_LEFT) {
                        op = CCodeBinaryOperator.SHIFT_LEFT;
                } else if (expr.operator == BinaryOperator.SHIFT_RIGHT) {