<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/moving-integer-division-to-floating-point-is-trivial-7s6ttpx3b" -->

---
title: Moving integer division to floating-point is trivial
description: Integer division and modulo operations have high latency and poor throughput on modern hardware, while floating-point division is faster with more execution...
canonical: https://daily.dev/posts/moving-integer-division-to-floating-point-is-trivial-7s6ttpx3b
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Moving integer division to floating-point is trivial | daily.dev
og:description: Integer division and modulo operations have high latency and poor throughput on modern hardware, while floating-point division is faster with more execution...
og:url: https://daily.dev/posts/moving-integer-division-to-floating-point-is-trivial-7s6ttpx3b
og:image: https://api.daily.dev/og/posts/7s6ttpx3B.png
og:image:alt: Moving integer division to floating-point is trivial
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Moving integer division to floating-point is trivial

**[MBR](https://daily.dev/sources/marc-b-reynolds)** · 4 min read · 1 upvotes · 2 comments

## Summary

Integer division and modulo operations have high latency and poor throughput on modern hardware, while floating-point division is faster with more execution units. This post proves that for integers fitting within 53 bits (double) or 24 bits (single precision), floating-point trunc(x/y) produces the exact same result as integer division, and -fma(d,y,-x) gives the exact remainder. The key insight is that floating-point division in base-2 at the same working precision has no tie cases, so round-to-nearest always rounds correctly. Practical considerations include SIMD usage to amortize conversion overhead, AVX-512 division with explicit rounding mode control, and the cost of int-to-float conversion on x64 for unsigned types.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <http://marc-b-reynolds.github.io/math/2026/08/10/IntDivByFP.html>

## Questions this post answers

### Can floating-point division be used to compute exact integer division results instead of using the CPU's integer divide instruction?

Yes, provided both integers fit within the floating-point format's mantissa precision (53 bits for double, 24 bits for single). Promoting the integers to floating point, computing trunc(x/y) for the quotient, and using an fma-based formula -fma(d,y,-x) for the remainder yields results identical to integer division and remainder, because floating-point division under round-to-nearest ties-to-even has no exact midpoints, so no rounding ties ever occur.

_Developers optimizing hot division paths can find deep dives like this floating-point trick on daily.dev._

### Why does round-to-nearest ties-to-even rounding never produce a tie in floating-point division?

Floating-point division in base-2 with equal working precision has zero exact midpoints between representable numbers, a result proven in formal work on midpoints and exact points of algebraic functions in floating-point arithmetic. Since a tie requires the exact result to land precisely at a midpoint, and no such midpoint exists for division, only the round-to-nearest rule ever applies, never the tie-breaking rule.

_Engineers reasoning about floating-point rounding edge cases can track proofs like this on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@trevorsuna** · 0 upvotes

> The exactness argument is the interesting part; this is more than a hand-wavy ‘floats are faster’ trick. The conversion cost and target ISA still decide whether it wins, so a benchmark around the real vector width and value range seems essential before replacing integer division.

**@agustinbarrientos** · 0 upvotes

> At what SIMD width does this beat native integer division after the unsigned conversions?

## Similar posts on daily.dev

- [\[2604.07902\] Optimization of 32-bit Unsigned Division by Constants on 64-bit Targets](https://daily.dev/posts/2604-07902-optimization-of-32-bit-unsigned-division-by-constants-on-64-bit-targets-uy09tvu32) · Hacker News · 0 upvotes · 0 comments
- [The First Thing I Check When I See Division in Solidity](https://daily.dev/posts/the-first-thing-i-check-when-i-see-division-in-solidity-2hwnlk7dc) · Coins Bench · 0 upvotes · 0 comments
- [research\!rsc: Fast Unrounded Scaling: Proof by Ivy \(Floating Point Formatting, Part 4\)](https://daily.dev/posts/research-rsc-fast-unrounded-scaling-proof-by-ivy-floating-point-formatting-part-4--iv1ppqckg) · research\!rsc · 0 upvotes · 0 comments

---

Tags: [#general-programming](https://daily.dev/tags/general-programming), [#performance](https://daily.dev/tags/performance)

[View this post on daily.dev](https://daily.dev/posts/moving-integer-division-to-floating-point-is-trivial-7s6ttpx3b)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Moving integer division to floating-point is trivial","url":"https://daily.dev/posts/moving-integer-division-to-floating-point-is-trivial-7s6ttpx3b","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/moving-integer-division-to-floating-point-is-trivial-7s6ttpx3b"},"datePublished":"2026-08-10T20:06:15.981Z","dateModified":"2026-09-13T20:45:12.455Z","description":"Integer division and modulo operations have high latency and poor throughput on modern hardware, while floating-point division is faster with more execution...","image":"https://media.daily.dev/image/upload/s--foaA6JGU--/f_auto/v1722860399/public/Placeholder%2004","thumbnailUrl":"https://media.daily.dev/image/upload/s--foaA6JGU--/f_auto/v1722860399/public/Placeholder%2004","isAccessibleForFree":true,"articleSection":"MBR","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"MBR","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/5dbef524bea24f3dbb75082281838b3b","url":"https://daily.dev/sources/marc-b-reynolds"},"commentCount":2,"discussionUrl":"https://daily.dev/posts/moving-integer-division-to-floating-point-is-trivial-7s6ttpx3b","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":2}],"keywords":"general-programming,performance","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"MBR","item":"https://daily.dev/sources/marc-b-reynolds"},{"@type":"ListItem","position":3,"name":"Moving integer division to floating-point is trivial"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/moving-integer-division-to-floating-point-is-trivial-7s6ttpx3b","comment":[{"@type":"Comment","text":"The exactness argument is the interesting part; this is more than a hand-wavy ‘floats are faster’ trick. The conversion cost and target ISA still decide whether it wins, so a benchmark around the real vector width and value range seems essential before replacing integer division.","datePublished":"2026-08-11T06:06:31.515Z","url":"https://daily.dev/posts/7s6ttpx3B#c-Kf2UkBALn","author":{"@type":"Person","name":"Trevor Suna","url":"https://daily.dev/trevorsuna","image":"https://media.daily.dev/image/upload/s--dZ7gXxpp--/f_auto/v1784081551/avatars/avatar_EMoP47rpuw8DNjhp6R1b6?_a=BAMAMicg0"}},{"@type":"Comment","text":"At what SIMD width does this beat native integer division after the unsigned conversions?","datePublished":"2026-08-11T08:27:23.629Z","url":"https://daily.dev/posts/7s6ttpx3B#c-eI6eXjRUT","author":{"@type":"Person","name":"Agustin Barrientos","url":"https://daily.dev/agustinbarrientos","image":"https://media.daily.dev/image/upload/s--5ayxQnqn--/f_auto/v1788281802/avatars/avatar_wQYYVe5Tbj0NJ7C7qPoa8?_a=BAMAMicg0"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/moving-integer-division-to-floating-point-is-trivial-7s6ttpx3b#faq","mainEntity":[{"@type":"Question","name":"Can floating-point division be used to compute exact integer division results instead of using the CPU's integer divide instruction?","acceptedAnswer":{"@type":"Answer","text":"Yes, provided both integers fit within the floating-point format's mantissa precision (53 bits for double, 24 bits for single). Promoting the integers to floating point, computing trunc(x/y) for the quotient, and using an fma-based formula -fma(d,y,-x) for the remainder yields results identical to integer division and remainder, because floating-point division under round-to-nearest ties-to-even has no exact midpoints, so no rounding ties ever occur. Developers optimizing hot division paths can find deep dives like this floating-point trick on daily.dev."}},{"@type":"Question","name":"Why does round-to-nearest ties-to-even rounding never produce a tie in floating-point division?","acceptedAnswer":{"@type":"Answer","text":"Floating-point division in base-2 with equal working precision has zero exact midpoints between representable numbers, a result proven in formal work on midpoints and exact points of algebraic functions in floating-point arithmetic. Since a tie requires the exact result to land precisely at a midpoint, and no such midpoint exists for division, only the round-to-nearest rule ever applies, never the tie-breaking rule. Engineers reasoning about floating-point rounding edge cases can track proofs like this on daily.dev."}}]}
```

