php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76578 ** operator and negative base
Submitted: 2018-07-04 12:13 UTC Modified: 2018-07-04 18:49 UTC
From: amenshchikov at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 7.2.7 OS: Debian 9
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-07-04 12:13 UTC] amenshchikov at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.operators.arithmetic
---
When I try to raise number -9 to the power of 0.5 (take a root of even degree), I have -3 as result. But I think that NaN should be a more correct in this case.

Test script:
---------------
echo -9**0.5;

Expected result:
----------------
NAN

Actual result:
--------------
-3

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-04 12:17 UTC] requinix@php.net
-Status: Open +Status: Wont fix -Package: PHP Language Specification +Package: *General Issues
 [2018-07-04 12:17 UTC] requinix@php.net
** having higher precedence than - was specifically discussed when the operator was being added.
http://php.net/manual/en/language.operators.precedence.php
https://wiki.php.net/rfc/pow-operator
 [2018-07-04 18:49 UTC] rasmus@php.net
Or in other words, what you are doing is -(9 ** 0.5) which is indeed -3.
If you really mean to raise -9 to 0.5, do (-9)**0.5 and you will see you get NAN
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 06:01:30 2024 UTC