# Doctests with approx

**URL:** https://discourse.julialang.org/t/doctests-with-approx/113962
**Category:** General Usage
**Tags:** documenter
**Created:** [May 7, 2024, 6:30pm UTC](https://discourse.julialang.org/t/doctests-with-approx/113962 "2024-05-07T18:30:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![moble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moble/32/23535_2.png) [@moble](https://discourse.julialang.org/u/moble)
#### Post date: [May 7, 2024, 6:30pm UTC](https://discourse.julialang.org/t/doctests-with-approx/113962/1 "2024-05-07T18:30:56Z")

</div>

Is there any way to use approximate equality tests in the doctests?

I have various numerical functions whose output changes by `eps()` or so with some regularity — apparently depending on all sorts of obscure choices made by julia and/or llvm. Is it possible to pass a flag to `jldtoctest` so that it doesn’t error if the expected and evaluated output are `approx` equal to each other? I would prefer not to distract with explicit calls to `round` or anything like that.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [May 7, 2024, 6:40pm UTC](https://discourse.julialang.org/t/doctests-with-approx/113962/2 "2024-05-07T18:40:22Z")

</div>

I don’t think it parses the output, it just compares strings? But the Documenter.jl manual has an [example using filters](https://documenter.juliadocs.org/stable/man/doctests/#Filtering-Doctests) to allow it to ignore the last few digits.

---

<div class="post-metadata">

### Author: ![moble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moble/32/23535_2.png) [@moble](https://discourse.julialang.org/u/moble)
#### Post date: [May 7, 2024, 7:16pm UTC](https://discourse.julialang.org/t/doctests-with-approx/113962/3 "2024-05-07T19:16:51Z")

</div>

> [@stevengj](#):
>
> I don’t think it parses the output, it just compares strings?

Makes sense.

> [@stevengj](#):
>
> But the [Documenter.jl](https://juliahub.com/ui/Packages/General/Documenter) manual has an [example using filters](https://documenter.juliadocs.org/stable/man/doctests/#Filtering-Doctests) to allow it to ignore the last few digits.

Ah, didn’t know about this. Thanks!

Lucky for me, I really only need to test ~12 digits after the decimal in any number in the documentation, so I can use a sledgehammer. I added this argument to the `makedocs` call:

```julia
    doctestfilters = [
        # Ignore any digit after the 12th digit after a decimal, throughout the docs
        r"(?<=\d\.\d{12})\d+",
    ],

```

Note that [this issue](https://github.com/JuliaDocs/Documenter.jl/issues/2360) means we currently can’t apply substitutions with this argument, but for me a [lookbehind](https://www.pcre.org/current/doc/html/pcre2syntax.html#SEC19) worked fine.
