Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neg and Dec #175

Closed
ryandotsmith opened this issue May 30, 2024 · 1 comment
Closed

Neg and Dec #175

ryandotsmith opened this issue May 30, 2024 · 1 comment

Comments

@ryandotsmith
Copy link

Hi. Thank you for your code. This might be out of scope, but I wondered if Dec() should be prefixed with a "-" when Sign < 0.

package main

import (
    "testing"

    "github.com/holiman/uint256"
)

func TestDec(t *testing.T) {
    a := uint256.MustFromHex("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
    if a.Dec() != "-1" {
        t.Errorf("want: -1 got: %s", a.Dec())
    }
    b := uint256.NewInt(0).Neg(uint256.NewInt(1))
    if b.Dec() != "-1" {
        t.Errorf("want: -1 got: %s", b.Dec())
    }
}
--- FAIL: TestDec (0.00s)
    main_test.go:12: want: -1 got: 115792089237316195423570985008687907853269984665640564039457584007913129639935
    main_test.go:16: want: -1 got: 115792089237316195423570985008687907853269984665640564039457584007913129639935
    ```
@holiman
Copy link
Owner

holiman commented Oct 2, 2024

The Neg function does not alter the fact that uint256 Ints are inherently unsigned. The Neg simply transforms it into another big unsigned number, which happens to be the negative complement.

But the Int has no internal notion of being negative, and cannot be made to output -

@holiman holiman closed this as completed Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants