php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66326 math oparation
Submitted: 2013-12-19 21:11 UTC Modified: 2013-12-19 21:13 UTC
From: ivo dot urbanek at yahoo dot co dot uk Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.23 OS: Win 7 x64 / openSUSE 12.3
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: ivo dot urbanek at yahoo dot co dot uk
New email:
PHP Version: OS:

 

 [2013-12-19 21:11 UTC] ivo dot urbanek at yahoo dot co dot uk
Description:
------------
Great problem with calculation power two - how easy, have a look 

B^2 = B*B

but not in PHP. Please run a example. If B = 12E4, than B*B is not B^2 !!!

Test script:
---------------
$A=1; $B=6.911824E4; $C=3.95554E8;
    
   // $D = $B^2-4*$A*$C; $sqr=sqrt($D);   echo "discriminant = $D <br>";
    
    $D = $B*$B;    echo "B*B = $D  <br>";
    $D = $B^2;     echo "B^2 = $D  <br>"; # <-- Here is deferent number !!!
    

   // $D = 4*$A*$C; echo "4*A*C = $D <br>";
    

Expected result:
----------------
B*B = 4777331100.6976 
B^2 = 69116                 # <-- Incorrect !


B*B = 4777331100.6976       # good answer

Actual result:
--------------
B^2 = 69116                 # <-- Incorrect !

Patches

power-two (last revision 2013-12-19 21:16 UTC by ivo dot urbanek at yahoo dot co dot uk)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-19 21:13 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2013-12-19 21:13 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

^ is a bitwise XOR, not a power/exponentiation operator.

Use pow().
http://www.php.net/pow
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 09:00:02 2026 UTC