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

internal: get rid of architecture specific constants #191

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/c/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import (
"math/big"
)

const (
is64bit = 1 << (^uintptr(0) >> 63) / 2 // 0 or 1
is32bit = is64bit &^ 1 // 0 or 1

maxScale32 = 425000000
maxScaleInf32 = 1000000001

maxScale64 = 999999999999999999
maxScaleInf64 = 2000000000000000001

MaxScale = maxScale32*is32bit + maxScale64*is64bit
MaxScaleInf = maxScaleInf32*is32bit + maxScaleInf64*is64bit
)

const Inflated uint64 = math.MaxUint64

var (
Expand Down
7 changes: 0 additions & 7 deletions internal/c/const32.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/c/const64.go

This file was deleted.

37 changes: 37 additions & 0 deletions internal/c/const_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package c

import (
"math/bits"
"testing"
)

func TestMaxScale(t *testing.T) {
check := func(t *testing.T, max int64, maxInf int64) {
if MaxScale != max {
t.Fatalf("MaxScale: got %d, expected %d", MaxScale, max)
}
if MaxScaleInf != maxInf {
t.Fatalf("MaxScaleInf: got %d, expected %d", MaxScaleInf, maxInf)
}
}
switch n := bits.UintSize; n {
case 32:
if is32bit != 1 {
t.Fatalf("is32bit: got %d, expected %d", is32bit, 1)
}
if is64bit != 0 {
t.Fatalf("is64bit: got %d, expected %d", is64bit, 0)
}
check(t, maxScale32, maxScaleInf32)
case 64:
if is32bit != 0 {
t.Fatalf("is32bit: got %d, expected %d", is32bit, 0)
}
if is64bit != 1 {
t.Fatalf("is64bit: got %d, expected %d", is64bit, 1)
}
check(t, maxScale64, maxScaleInf64)
default:
t.Fatalf("unknown bit size: %d", n)
}
}
Loading