Julia: isimag: what should it do?

Created on 9 Jan 2017  路  12Comments  路  Source: JuliaLang/julia

https://github.com/JuliaLang/julia/pull/19925#issuecomment-271185887 and the following discussion revealed lack of consensus regarding isimag's behavior. Clarifying isimag's behavior is this thread's purpose. Questions that prompted the original discussion: Should isimag(0) yield true or false? What about isimag(0+0im)? Thoughts? Best!

complex design maths

Most helpful comment

I also agree that we should deprecate isimag(z) to iszero(real(z)).

All 12 comments

As far as I can tell, nobody actually uses this function. It seems only to exist for consistency with isreal.

It's not used in any registered package as far as I can tell. I expect that it is only in Base because it was assumed to be needed for completeness, given isreal.

If we have it at all, I think the current definition isimag(z) = iszero(z.real) is the only sane one, but it might make more sense just to deprecate it.

Quoth the Jeff,

I'm not sure what this function is even for

I certainly sympathize with that. I would imagine that isimag = !isreal but that precise behavior is weird in practice. Deprecating it sounds like a good idea to me, unless we restrict it to complex inputs only.

I also agree that we should deprecate isimag(z) to iszero(real(z)).

Note that iszero is not yet exported, so we would need to export it first in order to use that deprecation.

iszero seems nice to have exported, but if there's a good reason it isn't exported, perhaps the deprecation could just be real(z) == 0.

iszero was added in #17623, where I suggested that it should be exported, but that PR was doing too many other things so I chose not to export iszero just to be conservative (and to avoid arguments over its semantics). A PR to export iszero would be welcome.

But I agree that real(z) == 0 is fine for deprecating isimag(z::Complex).

Note that iszero is not yet exported, so we would need to export it first in order to use that deprecation.

If isimag isn't much used, deprecating with Base.iszero(real(z)) seems reasonable? Avoids coupling deprecation of isimag to the question of exporting iszero.

Doing the deprecation and export together would actually work well, I would think, because if we deprecate in favor of Base.iszero but have iszero exported, that's kind of confusing. But as you said, if isimag isn't used much then likely few people would even notice the deprecation warning anyway.

Tentative deprecation PR using the Base.iszero(real(z)) approach at #19949. Best!

And exporting PR at #19950. 馃檪

Closed by #19949.

Was this page helpful?
0 / 5 - 0 ratings