Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaN raised to a power of zero returns 1 (not NaN) #340

Closed
Kolobamanacas opened this issue Nov 25, 2022 · 2 comments
Closed

NaN raised to a power of zero returns 1 (not NaN) #340

Kolobamanacas opened this issue Nov 25, 2022 · 2 comments

Comments

@Kolobamanacas
Copy link

Kolobamanacas commented Nov 25, 2022

Repro steps:

import BigNumber from "bignumber.js";

const number = new BigNumber('1 Definitely 2 not 3 a 4 number 5').exponentiatedBy(new BigNumber('0'));

console.log(number.toString()); // Prints 1 (not NaN).
console.log(number.toFixed()); // Prints 1 (not NaN).

I'm not sure whether this behavior is intentional or not, but it seems to me that any arithmetical operation including not-a-number must return not-a-number. Getting "1" creates false impression that operation is valid and was performed using valid operands, which, in my opinion, is not the case with not-a-numbers.

@MikeMcl
Copy link
Owner

MikeMcl commented Nov 25, 2022

Whether it would be better to return NaN is a moot point here as the power operation intentionally defers to Math.pow:

Math.pow(NaN, 0)    // 1

@Kolobamanacas
Copy link
Author

Hmm, I see. I wasn't aware of this Math's behavior, thanks. I don't think it's correct either, but I guess it's not the place from where we could change it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants