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

fix default unsigned integers judgment #145

Merged
merged 1 commit into from Jan 28, 2023

Conversation

Chasing1020
Copy link
Contributor

What problem does this PR solve?

  • I am using Apple M1 (GOARCH="arm64"; GOOS="darwin"; GOVERSION="go1.18.3") to test the proj6 but failed to pass the only case TestLockTTL.
  • The testLockSuite function ttlEquals should be set true when the arch is arm64, otherwise, the code will not be able to pass the test locally, although it works well on the Autograding machine.

What is changed and how it works?

I have written a demo as follows.

func main() {
    fmt.Printf("runtime.GOARCH: %s\n", runtime.GOARCH)
    var x, y uint64 = 73, 1040
    fmt.Printf("x: %d, y: %d\n", x, y)
    fmt.Printf("int(math.Abs(float64(x-y))): %d\n", int(math.Abs(float64(x-y))))
    fmt.Printf("int(-math.Abs(float64(x-y))): %d\n", int(-math.Abs(float64(x-y))))
}

It will get different results depending on whether the system is arm64 or amd64.

// in GOARCH="amd64" GOOS="linux"
runtime.GOARCH: amd64
x: 73, y: 1040
int(-math.Abs(float64(x-y))): -9223372036854775808
int(math.Abs(float64(x-y))): -9223372036854775808

// in GOARCH="arm64" GOOS="darwin"
runtime.GOARCH: arm64
x: 73, y: 1040
int(-math.Abs(float64(x-y))): -9223372036854775808
// c.Assert(int(math.Abs(float64(x-y))), LessEqual, 2) will failed
int(math.Abs(float64(x-y))): 9223372036854775807

In order to avoid unnecessary misunderstandings among students using the MacBook with Apple silicon, I suggest adding a condition runtime.GOARCH == "arm64" to the judgment.

@yanguwan yanguwan merged commit ff9ff36 into talent-plan:course Jan 28, 2023
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

Successfully merging this pull request may close these issues.

None yet

2 participants