`eps()` (epsilon) for Complex floats?

It is surprising to me that eps(Complex{Float32}) is unsupported currently, given that there are many applications involving complex data where one would like to specify the precision of some operation appropriately.

A single line addition to Base will address this:

eps(::Type{Complex{T}}) where T <: AbstractFloat = eps(T)

I realize that the docs for eps refer to “next largest value” and there is no ordering of complex numbers, but the principle applies adequately to the real and imaginary parts.

I can submit a PR to add this one line (and associated tests and docs) but I wanted to first get a sense of whether this addition seems appropriate to others.

BTW, in Matlab eps(1 + 1i) works and returns the same value as eps(1) so I think I’m not too far out on a limb here…

I’ve seen at least two package issues that arose due to this absence:
https://github.com/JuliaLang/julia/issues/34866
https://github.com/SciML/DifferentialEquations.jl/issues/287

Yeah. This is kind of weird. On the balance, it sounds like we should support this. Want to make a PR?

1 Like

edit: so much for it being just one added line :slight_smile:

There is already a PR: Support complex numbers in eps by ChrisRackauckas · Pull Request #21858 · JuliaLang/julia · GitHub

3 Likes

Yeah, this is exactly what brought it up, but I never got back to it. I don’t know when I’ll have the time to revive the PR either, so assume it’s open and take a stab at it if you want. It’s probably only like an hour or two away: just move some tests, make a small change, and make it a branch off of latest master.

1 Like