# Does mod() work? Or am I high?

**URL:** <https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093>\
**Category:** General Usage\
**Created:** [September 17, 2018, 8:33pm UTC](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093 "2018-09-17T20:33:11Z")\
**Posts on this page:** 1\
**Showing post:** 18

<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:** [September 18, 2018, 3:31pm UTC](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093/18 "2018-09-18T15:31:31Z")

</div>

> [@GlenHenshaw](#):
>
> The tempting thing to do, therefore, is to call time “t” and desired output rate “dt”, and call a routine to record the output whenever mod(t, dt) is approximately zero.

That seems dicey to me. If by “approximately zero” you mean `abs(mod(t, dt)) < ε` for some `ε`, then if you make `ε` too small you risk outputting very infrequently (because your code only gets called at a _discrete_ set of times `t`, which may not often be close to multiples of `dt`), and if you make `ε` too large then you risk outputting multiple times in the same `dt` time interval.

Why not do something like:

```julia
t = time()
if t >= last_output_time + dt
    ...output...
    last_output_time = t
end

```

That way it will call the output routine as close as possible to intervals of `dt`, limited by the frequency of the times `t` where you perform this check.

---

_[View the full topic](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093)._
