Stream: beginners

Topic: ✔ .div_floor_by(..)


view this post on Zulip Jasper Woudenberg (Jul 11 2026 at 16:52):

I noticed that for integer-division there exists div_trunc_by (rounds towards zero), div_ceil_by (rounds up), but not div_floor_by (would round down). Are there plans to still add div_floor_by?

In my date/time library I make use of the Neiri/Schneider algorithms, and these make use of div_floor_by-type integer division. Possibly there's an equivalent way to get the same output, but I don't really understand the algorithm I'm copying :sweat_smile:, so I'm pretty much doing a line-by-line transformation from the Zig-version of the algorithm. My current workaround of doing float division and then casting the result back to an integer is certainly suboptimal, hence the interest.

view this post on Zulip Richard Feldman (Jul 11 2026 at 17:11):

we should add it! :+1:

view this post on Zulip Richard Feldman (Jul 11 2026 at 17:11):

can you open an issue for that?

view this post on Zulip Jasper Woudenberg (Jul 11 2026 at 18:14):

Sure thing!
https://github.com/roc-lang/roc/issues/10085

view this post on Zulip Notification Bot (Jul 11 2026 at 18:14):

Jasper Woudenberg has marked this topic as resolved.

view this post on Zulip Richard Feldman (Jul 11 2026 at 18:28):

@Jasper Woudenberg how's this look? https://github.com/roc-lang/roc/pull/10086/changes

view this post on Zulip Jasper Woudenberg (Jul 11 2026 at 19:36):

Awesome! I was a bit surprised it needs some conditional logic around it and can't be lowered directly to assembly or something, but best I can tell from taking a look at the @divFloor primitive in Zig they have a similar thing going on.


Last updated: Jul 23 2026 at 13:15 UTC