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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Sat Sep 21 17:01:27 2019 UTC