Is it possible to set a floating point precision while evaluating jldoctest blocks in docstrings?

I’m not too familiar with Documenter, so this might have a solution that I’m not aware of. Is it possible to set a filter to compare only the first n digits of floating-point numbers in a jldoctest block? Either of a global or a local setting would be fine.

1 Like

It’s not quite perfect for this, but you can set regexes which filter out parts of the output before it’s compared: Doctests · Documenter.jl.

1 Like

@jishnub I would caution against this and make use of Julia’s operator (aka. isapprox) instead. Because IEEE754 floating-point numerical precision does not guarantee that any calculation be correct after some fixed number of decimals. Your tests would maybe appear to work at first, but they would be fundamentally broken IMO.

How can you use ≈ in a jldoctest?

@cmichelenstrofer With constructs like:

julia> my_matrix ≈ [
    0.58 0.55 0.53
    0    0.89 1.0
    1.45 22.5 -0.6
    ]
true 

I guess?