# 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:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 19, 2018, 8:40am UTC](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093/21 "2018-09-19T08:40:47Z")

</div>

If the software engineer is implementing it in pure C, how would they solve that problem? As far as I’m aware, `round` or any equivalents in C also don’t hide floating point inaccuracies and as such they regularly have to compare to some epsilon or use the method proposed above with the addition. It’s a basic standard for comparing floating point numbers and is being taught by default, as far as I’m aware (at least the CS courses I took always made sure we used that method and were aware of it).

---

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [September 19, 2018, 12:20pm UTC](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093/22 "2018-09-19T12:20:34Z")

</div>

Yeah, that’s my problem here as well. Using Rational is a brilliant solution and I would be on it like a shot, except that the embedded software engineers aren’t going to implement their own base type in C just for this.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 19, 2018, 12:36pm UTC](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093/23 "2018-09-19T12:36:03Z")

</div>

> [@GlenHenshaw](#):
>
> the embedded software engineers aren’t going to implement their own base type in C just for this

I was under the impression we are talking about Julia.

---

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [September 19, 2018, 1:00pm UTC](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093/24 "2018-09-19T13:00:59Z")

</div>

As I stated a few posts above, I have a unique issue. I’m prototyping algorithms in Julia, for eventually implementation in C on a realtime embedded target. Julia has proved brilliant as a prototyping language and as a result I am enthusiastically advocating for it among my group. But the target software is mission critical and Julia was never in the running.

---

<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 19, 2018, 1:34pm UTC](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093/25 "2018-09-19T13:34:58Z")

</div>

> [@GlenHenshaw](#):
>
> Using Rational is a brilliant solution and I would be on it like a shot, except that the embedded software engineers aren’t going to implement their own base type in C just for this.

I don’t know what you mean by a “base” type. A rational is just a pair of integers, and rational calculations on these are pretty easy to implement in C; just look at the Julia implementation in [base/rational.jl](https://github.com/JuliaLang/julia/blob/master/base/rational.jl).

That being said, [as I commented above](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093/18) I think the whole idea of looking for times that are exact multiples of `dt` is probably the wrong direction.

---

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [September 19, 2018, 2:04pm UTC](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093/26 "2018-09-19T14:04:28Z")

</div>

Yes, on reflection I think you are right. I’m going to rewrite it.

[Previous page](https://discourse.julialang.org/t/does-mod-work-or-am-i-high/15093.md?page=1)
