Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:46:00+00:00 2026-06-17T22:46:00+00:00

The ECMAScript specification for Math.pow has the following peculiar rule: If x < 0

  • 0

The ECMAScript specification for Math.pow has the following peculiar rule:

  • If x < 0 and x is finite and y is finite and y is not an integer, the result is NaN.

(http://es5.github.com/#x15.8.2.13)

As a result Math.pow(-8, 1 / 3) gives NaN rather than -2

What is the reason for this rule? Is there some sort of broader computer science or IEEEish reason for this rule, or is it just a choice TC39/Eich made once upon a time?


Update

Thanks to Amadan’s exchanges with me, I think I understand the reasoning now. I would like to expand upon our discussion for the sake of posterity.

Let’s take the following example: Math.pow(823543, 1 / 7) yields 6.999999999999999 although it really should be 7. This is an inaccuracy introduced by the fact that 1 / 7 must first be converted to a decimal representation 0.14285714285714285, which is truncated and loses precision. This isn’t such a bad problem when we’re working with positive numbers because we still get a result that’s extremely close to the real result.

However, once we step into the negative world we have a problem. If a JavaScript engine were to try to compute Math.pow(-823543, 1 / 7) it would first need to convert 1 / 7 to a decimal, so it would really be computing Math.pow(-823543, 0.14285714285714285) which actually has no real answer. In this case, it may have to return NaN since it couldn’t find a real number, even though the real answer should be -7. Futhermore, looking for complex numbers which are close to real numbers to make a “best guess” may involve a level of complexity they didn’t want to require a JS engine to have in the math arena.

My guess is it is due to the consideration of the loss of precision in floating point numbers that led them to the rule that negative numbers to a non-integer power should always be NaN — basically because a non-integer power is likely to give a complex number as a result of loss of precision, even if it shouldn’t, and there may be no good way to recover from it.

With this, I’m fairly satisfied, but I do welcome further information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:46:02+00:00Added an answer on June 17, 2026 at 10:46 pm

    I assume because those circumstances lead the result into complex waters, and ECMAScript is not equipped with imaginary numbers. Specifically, your example should result in something close to 1 + 1.732i, among other results. (The fact that -2 is also a possible result is besides the point – it is an accident rather than a rule.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ECMAScript 5 has the filter() prototype for Array types, but not Object types, if
I am aware of this site: http://wiki.ecmascript.org/doku.php However, I have not been able to
Please consider the official ECMAScript specification as the source for your answer, and not
The ECMAScript working group has started working on the next edition of the language.
According to the ECMAScript specification in section 7.8.1 a NullLiteral is defined as follows:
I have been studying the ECMAScript specification and have found that it is extremely
I am reading ECMAScript Language Specification Function Calls section Can someone rephrase or detailed
I know that the ECMA Script specification does not specify which algorithm to use
ECMAScript 5 has quite a few nice additions. John Resig has a good overview
The ECMAScript 5 spec states the following: Usually a Lexical Environment is associated with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.