-
Notifications
You must be signed in to change notification settings - Fork 54
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
Negative inexact raised to a power #12
Comments
I agree the behavior is undesirable: a real raised to an exact integer should result in a real. Here is a patch to master. I do not have time to test for regressions, so I hesitate to push it. diff --git a/schemeNumber.js b/schemeNumber.js
index b44fc24..b089623 100644
--- a/schemeNumber.js
+++ b/schemeNumber.js
@@ -3642,6 +3642,7 @@ function implementPluginLibrary(plugins) {
// Functions to be provided by number implementations.
var nativeToExactInteger, divideReducedNotByOne;
var exactRectangular, inexactRectangular;
+ var nativeToInexact;
// Imports from ECMAScript.
var g = plugins.get("es5globals");
@@ -3678,6 +3679,7 @@ function implementPluginLibrary(plugins) {
divideReducedNotByOne = plugins.get("divideReducedNotByOne");
exactRectangular = plugins.get("exactRectangular");
inexactRectangular = plugins.get("inexactRectangular");
+ nativeToInexact = plugins.get("nativeToInexact");
ZERO = plugins.get("ZERO");
ONE = plugins.get("ONE");
@@ -3970,6 +3972,8 @@ function implementPluginLibrary(plugins) {
function complex_or_exact_expt(n) {
if (isExact(this))
return expt_N_EI_fn(this, n);
+ if (isReal(this))
+ return nativeToInexact(Math_pow(this, n));
return Complex_expt_fn(this, n);
}
function tan_via_divide_sin_cos() { As for having to call toString() explicitly after the + operator, that is unavoidable. I would write |
Applied the patch and did'nt see any regressions in my (indirect and insufficient) set of tests. |
I believe the following illustrates some undesirable behavior.
Raising an inexact negative number to a (non-complex) power results in a complex number.
And, printing this number gives NaN unless the toString method is explicitly called.
The text was updated successfully, but these errors were encountered: