php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45330 Incorrect outcomes gmp_pow
Submitted: 2008-06-22 16:57 UTC Modified: 2009-01-21 19:43 UTC
From: duisters_k at hotmail dot com Assigned:
Status: Not a bug Package: GNU MP related
PHP Version: 5.2.6 OS: Win XP SP2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: duisters_k at hotmail dot com
New email:
PHP Version: OS:

 

 [2008-06-22 16:57 UTC] duisters_k at hotmail dot com
Description:
------------
When I use gmp_init(), gmp_pow gives incorrect answers.

Reproduce code:
---------------
<pre><?php
$iMessage = ord($_GET['message']);
$rText = gmp_init($iMessage);
$rRandE = gmp_init("7");
?>
Message:  <?=gmp_strval($rText)?> <!-- 88 -->
e:        <?=gmp_strval($rRandE)?> <!-- 7 -->
Message^e:<?=gmp_strval(gmp_pow($rText,$rRandE))?> 18979061712307928304713728 
88^7:     <?=gmp_strval(gmp_pow(88,7))?> 40867559636992 (It doesn't matter here whether I use strings or integers)
pow(88,7):<?=pow(88,7)?>    40867559637000


Expected result:
----------------
Line 8 should give the same outcome as line 9 and (aproximatly) 10

Actual result:
--------------
Different outcomes

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-22 17:08 UTC] pajoye@php.net
Can you give a comprehensible script without external values (no _GET)? and a clear output of this script and what you would expect, no need to comment it, only what the script outputs now and what you would like to have.

 [2008-06-24 15:49 UTC] duisters_k at hotmail dot com
Description:
------------
When I use gmp_init(), gmp_pow gives incorrect answers.

Reproduce code:
---------------
<pre><?php
$iMessage = 88;
$rText = gmp_init($iMessage);
$rRandE = gmp_init("7");
?>
Message:  <?=gmp_strval($rText)?>
e:        <?=gmp_strval($rRandE)?> <!-- 7 -->
Message^e:<?=gmp_strval(gmp_pow($rText,$rRandE))?>
88^7:     <?=gmp_strval(gmp_pow(88,7))?>
pow(88,7):<?=pow(88,7)?>

Expected result:
----------------
Message: 88 
e: 7 
Message^e:40867559636992 
88^7:     40867559636992 
pow(88,7):40867559637000

Actual result:
--------------
Message: 88 
e: 7 
Message^e:18979061712307928304713728 
88^7:     40867559636992 
pow(88,7):40867559637000
 [2009-01-21 19:43 UTC] jani@php.net
RTFM. Proto of this function:

resource gmp_pow  ( resource $base  , int $exp  )

Notice the text 'int' for 2nd parameter?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC