php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #54598
Patch 20110424bcpowmod_okano revision 2011-04-24 14:18 UTC by okano1220 at gmail dot com

Patch 20110424bcpowmod_okano for BC math related Bug #54598

Patch version 2011-04-24 14:18 UTC

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

Developer: okano1220@gmail.com

Index: raisemod.c
===================================================================
--- raisemod.c	(revision 1)
+++ raisemod.c	(working copy)
@@ -74,20 +74,23 @@
       bc_rt_warn ("non-zero scale in modulus");
 
   /* Do the calculation. */
-  rscale = MAX(scale, base->n_scale);
-  while ( !bc_is_zero(exponent TSRMLS_CC) )
-    {
-      (void) bc_divmod (exponent, BCG(_two_), &exponent, &parity, 0 TSRMLS_CC);
-      if ( !bc_is_zero(parity TSRMLS_CC) )
-	{
-	  bc_multiply (temp, power, &temp, rscale TSRMLS_CC);
-	  (void) bc_modulo (temp, mod, &temp, scale TSRMLS_CC);
-	}
+  if (!bc_compare(mod, BCG(_one_))) {
+      temp = bc_copy_num (BCG(_zero_));
+  } else {
+      rscale = MAX(scale, base->n_scale);
+      while ( !bc_is_zero(exponent TSRMLS_CC) )
+        {
+          (void) bc_divmod (exponent, BCG(_two_), &exponent, &parity, 0 TSRMLS_CC);
+          if ( !bc_is_zero(parity TSRMLS_CC) )
+    	{
+	      bc_multiply (temp, power, &temp, rscale TSRMLS_CC);
+	      (void) bc_modulo (temp, mod, &temp, scale TSRMLS_CC);
+	    }
 
-      bc_multiply (power, power, &power, rscale TSRMLS_CC);
-      (void) bc_modulo (power, mod, &power, scale TSRMLS_CC);
-    }
-
+          bc_multiply (power, power, &power, rscale TSRMLS_CC);
+          (void) bc_modulo (power, mod, &power, scale TSRMLS_CC);
+        }
+  }
   /* Assign the value. */
   bc_free_num (&power);
   bc_free_num (&exponent);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC