Paul Hoffman / IMC <[EMAIL PROTECTED]> wrote: > My ham-fisted, not-at-all-elegant Perl code is available for all to > see; it gets the exact results as Adam's C code from the document.
Nitpick: Whenever the C code from the document succeeds, the Perl code also succeeds and yields the same result. Whenever the C code fails because of overflow, the Perl code might succeed or might return garbage, because it does not check for overflow. I think the same overflow detection logic used in the C code can be used in the Perl code, the only question is what value to assign to maxint. 0x7FFFFFFF is probably safe for all Perl implementations, but it would be nice to do a sanity check. Here's one idea: Check whether 0x7FFFFFFF % 46349 == 41779 (it should). If it doesn't, then we don't have 31 bits of precision. Even if the test succeeds, that doesn't prove that we have 31 bits of precision, but my intuition is that it provides reasonable confidence. (46349 is the smallest prime greater than sqrt(0x7FFFFFFF).) AMC
