Skip to content

Small problem with DivMod #178

@IsraelGomes

Description

@IsraelGomes

Hello everyone

I was kind of using DivMod, when I got an unexpected remainder 0 for the following
z := uint256.MustFromDecimal("147120705406341664063220615392")
y := uint256.MustFromDecimal("1461501637330902918203679268441974103478767737394")
fmt.Println(z.DivMod(z, y, new(uint256.Int)))

output: 0 0

Using new receiver returns the correct result.
z = uint256.MustFromDecimal("147120705406341664063220615392")
y = uint256.MustFromDecimal("1461501637330902918203679268441974103478767737394")
fmt.Println(new(uint256.Int).DivMod(z, y, new(uint256.Int)))

output: 0 147120705406341664063220615392

I think the error might be in line 619 to 621 of uint256.go
Since in my use z and x are equal, clear z will make m turn zero as well right?
if x.Lt(y) {
return z.Clear(), m.Set(x)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions