Re: A New Challenge Message #12 Posted by hugh on 22 Jan 2003, 6:49 a.m., in response to message #11 by Katie Wasserman
yes thats right. adjusting the mantissa was the method i used recently implementing
a working mod function. for a number `x', i had to scale it into y * 10^e where y
is a ndigit integer and n is your calculator precision. eg 10 (i was using n = 30).
this is especially important if `x' internally is binary. then you do,
mod(mod(y,m)*mod(10^e, m),m) and 10^e is done by binary powering.
there's more. the second problem is you also need doubleprecision arithmetic. if
you are 10 digit accurate, you need 20 internally. consider calculating a = 1e10,
b = 3.141592654 (dont call this pi for another reason) and find mod(a, b)
the right 10 digit answer is: 1.326632906, thats because internally you had to
work with a/b = 3183098861.4222803693 in order to get 10 final digits correct.
even more amusing are mods truly involving pi or 2pi, like those required to
perform sin, cos or tan. try sin(1e50), the right answer is: .7896724934
because the problem is actually sin(mod(1e50,2pi)). these mods are even
harder because you need a table of around 100 digits internally of 1/2pi to
perform mod(10^n,2pi).
some time ago, i wrote a page on this, but its not very well explained.
http://www.voidware.com/modsecret.htm
