php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #53397
Patch ModuloForDouble revision 2010-11-24 14:13 UTC by mryaggi at hotmail dot com

Patch ModuloForDouble for Scripting Engine problem Bug #53397

Patch version 2010-11-24 14:13 UTC

Return to Bug #53397 | Download this patch
Patch Revisions:

Developer: mryaggi@hotmail.com

Index: C:/source/Ressources/php-src/Zend/zend_operators.c
===================================================================
--- C:/source/Ressources/php-src/Zend/zend_operators.c	(revision 304134)
+++ C:/source/Ressources/php-src/Zend/zend_operators.c	(working copy)
@@ -975,8 +975,6 @@
 	zval op1_copy, op2_copy;
 	long op1_lval;
 
-	zendi_convert_to_long(op1, op1_copy, result);
-	op1_lval = Z_LVAL_P(op1);
 	zendi_convert_to_long(op2, op2_copy, result);
 
 	if (Z_LVAL_P(op2) == 0) {
@@ -990,8 +988,17 @@
 		ZVAL_LONG(result, 0);
 		return SUCCESS;
 	}
-
-	ZVAL_LONG(result, op1_lval % Z_LVAL_P(op2));
+	//If Op1 is a double, then : casting to long and using % is not accurate enough
+	if (Z_TYPE_P(op1) == IS_DOUBLE)
+	{
+		ZVAL_DOUBLE(result, op1_lval - ( floor(op1_lval/Z_LVAL_P(op2))*Z_LVAL_P(op2) );
+	}
+	else
+	{
+		zendi_convert_to_long(op1, op1_copy, result);
+		op1_lval = Z_LVAL_P(op1);
+		ZVAL_LONG(result, op1_lval % Z_LVAL_P(op2));	
+	}
 	return SUCCESS;
 }
 /* }}} */
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Feb 20 05:01:26 2019 UTC