# Re: \[PATCH v3 1/5\] math64: New DIV\_U64\_ROUND\_CLOSEST helper

- From: Andy Shevchenko \<hidden\>
- Date: 2021-07-19 12:47:50 
- List: linux-arm-kernel
- Page: https://ratatoskr.run/linux-arm-kernel/2021/07/1449119
- Thread: https://ratatoskr.run/linux-clk/2021/06/1425406/t.md

```text
On Sat, Jul 17, 2021 at 3:39 PM Pali Rohár [ref] wrote:
>
> Provide DIV_U64_ROUND_CLOSEST helper which uses div_u64 to perform
> division rounded to the closest integer using unsigned 64bit
> dividend and unsigned 32bit divisor.

...

> +/*
> + * DIV_U64_ROUND_CLOSEST - unsigned 64bit divide with 32bit divisor rounded to nearest integer

> + * @dividend: unsigned 64bit dividend

Here you insist users to provide a u64 (or compatible) type.

> + * @divisor: unsigned 32bit divisor
> + *
> + * Divide unsigned 64bit dividend by unsigned 32bit divisor
> + * and round to closest integer.
> + *
> + * Return: dividend / divisor rounded to nearest integer
> + */
> +#define DIV_U64_ROUND_CLOSEST(dividend, divisor)       \

> +       ({ u32 _tmp = (divisor); div_u64((u64)(dividend) + _tmp / 2, _tmp); })

Here is the casting to u64. Why? (Yes, I have read v1 discussion and I
just want to continue it here).

-- 
With Best Regards,
Andy Shevchenko

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
```
