Modulo in Golang

Written by
reddit
Link to Post

https://www.reddit.com/r/golang/comments/bnvik4/modulo_in_golang/ by 

I’m getting a little annoyed with the fact that every time I use math.Mod I’m having to check if it returned a negative value and then fix it so it’s in line with the modulo function https://en.wikipedia.org/wiki/Modular_arithmetic

1 mod 3 = 1 -1 mod 3 = 2 math.Mod(1, 3) = 1 math.Mod(-1, 3) = -1 1 % 3 = 1 -1 % 3 = -1 

(I know it’s called ‘remainder’ in the spec; it’s not claiming to be a modulo operation)

Who uses the negative return values in the real world?

submitted by /u/stewi1014
[link] [comments]

Article Tags:
· ·
Article Categories:
reddit

Leave a Reply