Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Added the Powers of Complex Numbers #485

Closed
wants to merge 20 commits into from

Conversation

emiljanogj
Copy link
Contributor

It supports a complex number to the power of: complex number, int, float, bool, class, bytes, range, str, set, frozenset, dict.

return powu(x, y)
}
if (Number(y) >= MAX_INT) {
if (Number(y) <= MAX_FLOAT) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always true except for Infinity (ditto below for MIN_FLOAT and -Infinity). So, it may not be necessary to have the MIN_FLOAT and MAX_FLOAT constants, and just check for infinities directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I have to consider 2 cases: 1. the number is greater than MAX_INT and smaller than MAX_FLOAT. If this is the case display the message exponentiation error. Otherwise, display the error message: number to big to be converted to float.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but Number(y) will just return Infinity if it is greater thanMAX_FLOAT, so the comparison is not needed -- you can just check if it is infinity.

}
return r
}
function powu(x, y) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it only works for positive integer y, but below it could be called with a positive real number?

Copy link
Contributor

@swenson swenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress so far! A few comments, and it looks like tests are passing yet.

@emiljanogj
Copy link
Contributor Author

@swenson I cannot understand why in the last test there are some test cases with two values for the base.

@swenson
Copy link
Contributor

swenson commented Apr 17, 2017

The built-in pow function accepts three arguments: it computes pow(a, b, m) = (a**b)%m efficiently. This form only supports integers though.

@shaib shaib mentioned this pull request May 27, 2018
4 tasks
@martica martica mentioned this pull request May 25, 2019
4 tasks
@martica
Copy link
Contributor

martica commented May 25, 2019

Thanks for all your work on this @EGJ1996. I picked up @shaib's version of this and got it up to date and merged.

@martica martica closed this May 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants