example input: # + and - mixed
-3942323
56456
-3
-342
-33398
683
output : #always positive value
3942323
56456
3
342
33398
683
i know abs() method returns the absolute value of a number and √(x^2) = all value positive
i need math steps
example:
https://www.wolframalpha.com/input/?i=3942323%2F-1+*++-1
https://www.wolframalpha.com/input/?i=-3942323%2F-1+*++-1
√(x^2) = only rootsqure alternative method maths explain please #mybad english
For example if the modulus is 7 then -1 becomes 6 or -9 becomes 5.
Essentially we compute (a mod m) then if the result was negative we add modulus to the result.
-9%7=-2 -> -2+7=5 -> -9 ≡ -2 ≡ 5 (mod 7)
As for square root, it is also different in modular arithmetic. You have to compute r so that r2≡a (mod p).
For secp256k1 curve we have a simple solution to compute ModPow(a, (p+1)/4, p) but in general cases where p%4 != 3 we have to use an algorithm like Tonelli–Shanks.