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
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: amenshchikov at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 17:01:34 2025 UTC