Conversation
batavia/types/Complex.js
Outdated
return powu(x, y) | ||
} | ||
if (Number(y) >= MAX_INT) { | ||
if (Number(y) <= MAX_FLOAT) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
@swenson I cannot understand why in the last test there are some test cases with two values for the base. |
The built-in |
Thanks for all your work on this @EGJ1996. I picked up @shaib's version of this and got it up to date and merged. |
It supports a complex number to the power of: complex number, int, float, bool, class, bytes, range, str, set, frozenset, dict.