File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -1329,13 +1329,23 @@ BENCHMARK(integral_division_by_const);
13291329 * Since 64-bit doubles can exactly represent all 32-bit signed integers,
13301330 * this method introduces @b no precision loss, making it a safe and efficient
13311331 * alternative when division performance is critical.
1332+ *
1333+ * - The `float` can fit 24-bit integers exactly in its significand/mantissa.
1334+ * - The `double` can fit 52-bit integers exactly in its significand/mantissa.
13321335 */
1336+ static void integral_division_with_floats (bm::State &state) {
1337+ std::int32_t a = std::rand (), b = std::rand (), c = 0 ;
1338+ for (auto _ : state)
1339+ bm::DoNotOptimize (c = static_cast <std::int32_t >(static_cast <float >(++a) / static_cast <float >(++b)));
1340+ }
1341+
13331342static void integral_division_with_doubles (bm::State &state) {
13341343 std::int32_t a = std::rand (), b = std::rand (), c = 0 ;
13351344 for (auto _ : state)
13361345 bm::DoNotOptimize (c = static_cast <std::int32_t >(static_cast <double >(++a) / static_cast <double >(++b)));
13371346}
13381347
1348+ BENCHMARK (integral_division_with_floats);
13391349BENCHMARK (integral_division_with_doubles);
13401350
13411351/* *
You can’t perform that action at this time.
0 commit comments