#python vs golang modulus

6 messages · Page 1 of 1 (latest)

steel python
#
>>> print(-10286371 % 12289)
11811

i want to get the same ans in GO
I tried all 3 methods but I get the same ans everytime

>>> fmt.Println((-10286371 % 12289))
-478

>>> fmt.Println(math.Mod(float64(-10286371), float64(12289)))
-478

>>> fmt.Println(math.Remainder(float64(-10286371), float64(12289)))
-478

wide belfry
#

!go go fmt.Println(-10286371 % 12289)

#

oh bot doesnt work

#

In computing, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another (called the modulus of the operation).
Given two positive numbers a and n, a modulo n (often abbreviated as a mod n) is the remainder of the Euclidean division of a by n, where a is the dividend and n is the divisor....

steel python
#

found solution

// Positive modulo, returns non negative solution to x % d
func Pmod(x, b int) int {
    x = x % b
    if x >= 0 {
        return x
    }
    if b < 0 {
        return x - b
    }
    return x + b
}