On Thu, 10 Oct 2024 21:54:27 GMT, Raffaello Giulietti <rgiulie...@openjdk.org> 
wrote:

>> Could make sense using Math.round() instead of Math.ceil() to get better 
>> upper bound?
>
> I'll have to check...
> ... tomorrow ;-)

IIUC, the code assumes that the floating-point computation 
`Math.ceil(intVal.bitLength() * LOG_5_OF_2)` has the same value as the 
mathematical &lceil; `intVal.bitLength()` &times; log5(2) &rceil;.
I don't think this is safe, as it might happen that the computed and 
mathematical values are off by &plusmn;1.
To ensure 5^`maxPowsOf5` >= `intVal` (that is, maxPowsOf5 >= log5(intVal)) it 
would be more prudent to have

long maxPowsOf5 = (long) Math.ceil(intVal.bitLength() * LOG_5_OF_2) + 1;


But I think what you really want is maybe to meet 5^`maxPowsOf5` <= `intVal` < 
5^(`maxPowsOf5` + 1) instead?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21323#discussion_r1797246974

Reply via email to