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
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: 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

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: Sat Apr 27 00:01:30 2024 UTC