[vala] Use fmod/fmodf for modulo operation between floating point values



commit 1b358f3e4da2c59af2b7757db686935a37738a16
Author: Luca Bruno <lethalman88 gmail com>
Date:   Thu Mar 11 12:10:03 2010 +0100

    Use fmod/fmodf for modulo operation between floating point values
    
    Fixes bug 610660.

 codegen/valaccodebasemodule.vala |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index fe9d70e..c7c6f81 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]