in reply to Re^2: Simple arithmetic? (And the winner is ... )
in thread Simple arithmetic?
FWIW: Of many things I've tried to improve on Anonymous Monk's gcm(), the only thing that has worked is this:
U64 gcm4( U64 max, U64 n ) { U64 c, lcm; for( c = 1; ( ~n & 1 ) && ( c < 12 ); ++c ) n >>= 1; lcm = n * 4096; return ( max / lcm ) * lcm; }
Incrementing seems to be fractionally faster than shifting:
anonyM: gcm for s=2147483648 & r=1 to 1073741824 took:33.850345514550 + ### original anonyM: gcm4 for s=2147483648 & r=1 to 1073741824 took:33.590549831120 + ### my tweak
But the difference, 1/4 second on > 1 billions calls is so minimal (0.2 nanoseconds), and the shifting better captures the semantics, I've stuck with the original.
|
|---|