apple / swift-numerics

Advanced mathematical types and functions for Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Complex(length: 0, phase: .infinity) should produce (0, 0)

NevinBR opened this issue · comments

Currently, Complex.init?(length: 0, phase: .infinity) produces nil.

However, when the length of a Complex number is identically 0, the phase is irrelevant and the value is always exactly (0, 0). This is even true for non-finite phase, because the length is still 0.

Thus, the polar initializer for Complex should produce (0, 0) when the input length is 0, regardless of the phase.

Does that means 0 * cis(.infinity) where cis(x) = cos(x) + i sin(x)?
https://www.wolframalpha.com/input/?i=0+*+cis%28infinity%29

I'll note that this proposed behavior is in direct contradiction to what you wrote in your other issue:

This is the same result one would get by first calculating the sine and cosine of the phase as a RealType then constructing the Complex result from its components

.cos(.infinity) is .nan, which gives .nan when multiplied by anything. Between the two, this one is more reasonable; cos(.infinity) is .nan, but mathematically cos and sin are bounded for all real inputs, so multiplying by zero should give zero.

Once there's some discussion and a rough consensus, this would be an easy starter bug for someone to address. Please wait for consensus, though.

I'll note that this proposed behavior is in direct contradiction to what you wrote in your other issue:

Yep, I thought of this while writing that one, but figured they should be considered separately.

Ideally (in my opinion) we’d do both: make the polar initializer non-failable, and make 0 length triumph over non-finite angle.

Just to give an additional opinion: I agree to your statement, that ...

Between the two, this one is more reasonable: cos(.infinity) is .nan, but mathematically cos and sin are bounded for all real inputs, so multiplying by zero should give zero.

For me a mathematical argumentation is the right way to go.

@NevinBR let's close this one and figure out what to do with the init more generally in #51.