On Mon, 15 Sep 2025 16:50:03 GMT, Joe Darcy <da...@openjdk.org> wrote:

>> fabioromano1 has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Optimization
>
> HI @fabioromano1,
> Ah, I haven't worked on that code for exact divide in a while!
> For some historical context, the method was added as part of JSR 13, Decimal 
> Arithmetic Enhancement, in JDK 5. A fuller derivation of the old bound is 
> discussed in:
> 
> Fixed, Floating, and Exact Computation with Java's BigDecimalFixed, Floating, 
> and Exact Computation with Java's BigDecimal
> Dr. Dobb's Journal ยท Jun 1, 2004
> https://web.archive.org/web/20210505132021/http://www.drdobbs.com/jvm/fixed-floating-and-exact-computation-wit/184405721
> 
> At the time I wrote the code, I looked around at the usual sources, Knuth, 
> etc. and asked around for a bound of decimal digits of 1/b if 1/b is 
> representable, but didn't find anything.
> 
> I see you're still revising the implementation. Once this settles down, a 
> review comment from me will be "restore some textual discussion of what the 
> algorithm is doing."
> 
> For testing, I think it would be good to probe at some values where the old 
> and new digit estimation techniques differ.
> 
> Also, I think both @rgiulietti and myself look at this PR before it goes 
> back; I'll adjust the reviewer count accordingly.

@jddarcy The technique used here is the following: take $a/b$, compute $b' = 
b/(2^i 5^j)$, where $i = \max(n \in N \mid b \equiv 0 \mod 2^n)$ and $j = 
\max(n \in N \mid b \equiv 0 \mod 5^n)$. If $a \not\equiv 0 \mod b'$, then 
$a/b$ is not a finite decimal number. Otherwise:

- if $i \le j$, then $a/b = (a/b')*2^{j-i} * 10^{-j}$;
- if $i > j$, then $a/b = (a/b')*5^{j-i} * 10^{-i}$.

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

PR Comment: https://git.openjdk.org/jdk/pull/27271#issuecomment-3293326363

Reply via email to