math - How to get the true Euclidean remainder? -


i have 2 unsigned longs a , q , find number n between 0 , q-1 such n + divisible q (without overflow).

in other words, i'm trying find (portable) way of computing (-a)%q lies between 0 , q-1. (the sign of expression implementation-defined in c89.) what's way this?

what you're looking mathematically equivalent (q - a) mod q, in turn equivalent (q - (a mod q)) mod q. think should therefore able compute follows:

 unsigned long result = (q - (a % q)) % q; 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -