On Thu, 16 Feb 2023 16:51:43 GMT, Raffaello Giulietti <rgiulie...@openjdk.org> wrote:
> After making sure that `intVal` is even, and before attempting a division by > a power of 10, it might help to check if 5 divides `intVal` in the first > place. If it doesn't, there no point in performing the division. > > It can be shown that 5 divides `intVal` if and only if it divides the `long` > sum of all `int`s in the `mag` array of `intVal`. > > I didn't try out if this contributes to improve the overall performance, but > it might be worth giving a try. [Here](https://github.com/plokhotnyuk/jsoniter-scala/commit/a92a4a6dbf3a51320c677e812d3495f1fa78255a#diff-4e32fbdaa814b6b0b8e22a1b1440bb2928e50a6e1482e0d56c08d606812b625bL1971) is the Scala function that tests divisibility by 5 for a positive `Long` value efficiently with minimum multiplication operations and can be easily adopted for Java. ------------- PR: https://git.openjdk.org/jdk/pull/12509