-
Notifications
You must be signed in to change notification settings - Fork 34
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
Modified the handling of zero and infinity to map to the Riemann sphere. #17
Changes from 1 commit
12c2ad3
2a60eb0
9454b7c
4b2a847
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,36 @@ var tests = [{ | |
}, { | ||
set: "2.3", | ||
expect: "2.3" | ||
}, { | ||
set: "0", | ||
expect: "0" | ||
}, { | ||
set: "-0", | ||
expect: "0" | ||
}, { | ||
set: {re: -0, im: 0}, | ||
expect: "0" | ||
}, { | ||
set: {re: 0, im: -0}, | ||
expect: "0" | ||
}, { | ||
set: Infinity, | ||
expect: "Infinity" | ||
}, { | ||
set: -Infinity, | ||
expect: "Infinity" | ||
}, { | ||
set: {re: Infinity, im: 0}, | ||
expect: "Infinity" | ||
}, { | ||
set: {re: -Infinity, im: 0}, | ||
expect: "-Infinity" | ||
expect: "Infinity" | ||
}, { | ||
set: {re: 0, im: Infinity}, | ||
expect: "Infinity" | ||
}, { | ||
set: {re: 0, im: -Infinity}, | ||
expect: "Infinity" | ||
}, { | ||
set: Complex.I, | ||
fn: "mul", | ||
|
@@ -83,7 +110,7 @@ var tests = [{ | |
set: Infinity, | ||
fn: "mul", | ||
param: "i", | ||
expect: "NaN" | ||
expect: "Infinity" | ||
}, { | ||
set: "-36i", | ||
fn: "sqrt", | ||
|
@@ -92,7 +119,27 @@ var tests = [{ | |
set: "4 + 2i", | ||
fn: "div", | ||
param: "0", | ||
expect: "Infinity + Infinityi" | ||
expect: "Infinity" | ||
}, { | ||
set: "0", | ||
fn: "div", | ||
param: Infinity, | ||
expect: "0" | ||
}, { | ||
set: -Infinity, | ||
fn: "div", | ||
param: 0, | ||
expect: "Infinity" | ||
}, { | ||
set: Infinity, | ||
fn: "div", | ||
param: Infinity, | ||
expect: "NaN" | ||
}, { | ||
set: 0, | ||
fn: "div", | ||
param: 0, | ||
expect: "NaN" | ||
}, { | ||
set: "4 + 2i", | ||
fn: "div", | ||
|
@@ -118,11 +165,26 @@ var tests = [{ | |
fn: "mul", | ||
param: "i", | ||
expect: "6 + 3i" | ||
}, { | ||
set: Infinity, | ||
fn: "mul", | ||
param: 0, | ||
expect: "NaN" | ||
}, { | ||
set: "3 + 4i", | ||
fn: "add", | ||
param: "5 - 7i", | ||
expect: "8 - 3i" | ||
}, { | ||
set: Infinity, | ||
fn: "add", | ||
param: Infinity, | ||
expect: "NaN" | ||
}, { | ||
set: -Infinity, | ||
fn: "sub", | ||
param: -Infinity, | ||
expect: "NaN" | ||
}, { | ||
set: "6i", | ||
fn: "div", | ||
|
@@ -155,7 +217,7 @@ var tests = [{ | |
}, { | ||
set: 0, | ||
fn: "log", | ||
expect: "-Infinity" | ||
expect: "Infinity" | ||
}, { | ||
set: Infinity, | ||
fn: "mul", | ||
|
@@ -321,7 +383,7 @@ var tests = [{ | |
set: -Infinity, | ||
fn: "div", | ||
param: 3, | ||
expect: "-Infinity" | ||
expect: "Infinity" | ||
}, { | ||
set: {re: 1, im: 2}, | ||
fn: "add", | ||
|
@@ -385,7 +447,7 @@ var tests = [{ | |
set: "0-0i", | ||
fn: "pow", | ||
param: 0, | ||
expect: "0" | ||
expect: "1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the rationale behind "0^0"=1? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as x -> 0, x^x -> 1 could be the reason There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that makes sense. But typically 0^0 is undefined. So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a very good point. It seems like it should be either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say let's go with |
||
}, { | ||
set: "1 + 4i", | ||
fn: "sqrt", | ||
|
@@ -470,6 +532,10 @@ var tests = [{ | |
}, { | ||
set: "0", | ||
fn: "inverse", | ||
expect: "Infinity" | ||
}, { | ||
set: Infinity, | ||
fn: "inverse", | ||
expect: "0" | ||
}, { | ||
set: Complex['EPSILON'], | ||
|
@@ -644,7 +710,7 @@ describe("Complex Details", function () { | |
assert.equal(one.mul(one).toString(), Complex(0, 2).toString()); | ||
assert.equal(one.div(2).toString(), "0.5 + 0.5i"); | ||
assert.equal(one.div(one).toString(), "1"); | ||
assert.equal(one.div(0).toString(), "Infinity + Infinityi"); | ||
assert.equal(one.div(0).toString(), "Infinity"); | ||
assert.equal(one.exp().toString(), "1.4686939399158851 + 2.2873552871788423i"); | ||
assert.equal(one.log().toString(), "0.34657359027997264 + 0.7853981633974483i"); | ||
assert.equal(one.pow(one).toString(), "0.2739572538301211 + 0.5837007587586147i"); | ||
|
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.
I would prefer calling this
ComplexInfinity
or simliar to make it clear that this is different from the real infinity that people are used to in JavaScriptThere 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.
I suppose the same could be said for the
NAN
. But since they are all CAPS and prefixed by the type (Complex.INFINITY
andComplex.NAN
) I am not sure the clarification is necessary. Doesn't matter to me though...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.
Even if
ComplexInfinity
is more unambiguous, I likeComplex.INFINITY
andComplex.NAN
better, since you would normally use it exactly as "Complex.INFINITY" and so it states already what ComplexInfinity wants to express.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.
I guess the question is how strongly do you feel about having the uppercase names. People are used to writing
NaN
rather thanNAN
so the upper case version may be confusing.