Hi all, long time reader, first time poster
Let me preface this with saying I am asking this question from the standpoint of a competitive programmer (competitions like TopCoder and ACM ICPC).
My question is this: does anyone know how Java implements mod? Specifically, if you type in a%b, does java simply interpret this as a-(a/b)*b, or does it do something more efficient?
I've done some problems recently in which mod has been called *a lot* of times, and am looking for ways to make the calls more efficient.
Thanks,
Stephen
Modular Arithmetic
Started by knightry, Jun 24 2009 11:47 AM
3 replies to this topic
#1
Posted 24 June 2009 - 11:47 AM
|
|
|
#2
Posted 01 July 2009 - 09:08 AM
So, nobody has any idea?
#3
Posted 01 July 2009 - 10:44 AM
Well, since Java is open-source, you could look at the code, but it probably depends on the individual processor. If the CPU implements mod, why "implement" it in Java?
#4
Posted 01 July 2009 - 03:24 PM
WingedPanther said:
Well, since Java is open-source, you could look at the code, but it probably depends on the individual processor. If the CPU implements mod, why "implement" it in Java?
Since Java needs to be compatible across all platforms, I have heard implementations of the JRE sometimes don't rely on the processor, directly, for calculations. I believe this only applies to floating point calculations, however.
You seek r where a = r (mod n). Most likely used if hardware cannot is, as you guessed, r = a - n floor(a/n). However, if n = 2k then r = and(a, n-1). Do you know anything about a or n?


Sign In
Create Account

Back to top









