bn.js internally keeps red numbers as big numbers modulo certain n. So calling umod on red number in bn.js is doing nothing as the number is already smaller than n. However, in our library we store red numbers in [montgomery form]https://en.wikipedia.org/wiki/Montgomery_modular_multiplication to speed up multiply and power operations.
We didn't expect anyone to call umod on a red number as the method is not marked as red. This pr fixes that by changing the result number in the red number what solves the problem.
An alternative approach would be to just make umod noop for red numbers as they are already less than module (because they are red numbers). However, I can think of some examples when we want to check number parity or few optimisations that relay on umod to avoid expensive redDiv calls.
bn.js internally keeps red numbers as big numbers modulo certain n. So calling
umod
on red number in bn.js is doing nothing as the number is already smaller than n. However, in our library we store red numbers in [montgomery form]https://en.wikipedia.org/wiki/Montgomery_modular_multiplication to speed up multiply and power operations. We didn't expect anyone to callumod
on a red number as the method is not marked as red. This pr fixes that by changing the result number in the red number what solves the problem.An alternative approach would be to just make
umod
noop for red numbers as they are already less than module (because they are red numbers). However, I can think of some examples when we want to check number parity or few optimisations that relay onumod
to avoid expensive redDiv calls.Fixes: https://github.com/margelo/react-native-bignumber/issues/55