php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78187 Exponentiation operator gives incorrect result
Submitted: 2019-06-20 08:40 UTC Modified: 2019-06-20 08:45 UTC
From: francis dot crossen at gmail dot com Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 7.3.6 OS: n/a
Private report: No CVE-ID: None
 [2019-06-20 08:40 UTC] francis dot crossen at gmail dot com
Description:
------------
Tested in PHP shell on Linux and Windows

Test script:
---------------
<?php

// expect 1
echo -1 * -1 . PHP_EOL;
echo pow(-1, 2) . PHP_EOL;
echo -1 ** 2 . PHP_EOL;

// expect 49
echo -7 * -7 . PHP_EOL;
echo pow(-7, 2) . PHP_EOL;
echo -7 ** 2 . PHP_EOL;




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-20 08:45 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2019-06-20 08:45 UTC] nikic@php.net
-1 ** 2 is -(1**2).

I would recommend to avoid spaces around ** to indicate that this is a high-precedence operator.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 02:01:29 2024 UTC