Ejemplo n.º 1
0
func BenchmarkCbrtIntgr(b *testing.B) {
	k := uint(1)
	if k<<32 != 0 {
		k = 32
	} else {
		k = 0
	}
	for i := 0; i < b.N; i++ {
		for j := 0x10000; j < 0x4000000; j += 0x10000 {
			_ = intgr.Cbrt(j << k)
		}
	}
}
Ejemplo n.º 2
0
func TestCrt(t *testing.T) {
	t.Logf("Testing Crt\n")
	// 32 bits -> 10 bits max number
	// 64 bits -> 21 bits max number
	i32Max := int32(1<<10 - 1)
	i64Max := int64(1<<21 - 1)
	u32Max := uint32(1<<10 - 1)
	u64Max := uint64(1<<21 - 1)

	iMax := 1
	var uMax uint
	if iMax<<32 == 0 {
		iMax = int(i32Max)
		uMax = uint(u32Max)
	} else {
		iMax = int(i64Max)
		uMax = uint(u64Max)
	}
	for i := iMax; i > 0; i >>= 1 {
		k := intgr.Cbrt(i * i * i)
		if k != i {
			t.Logf("intgr.Cbrt(%X*%X*%X) == %X\n", i, i, i, k)
			t.Fail()
		}
		k = intgr.Cbrt(-(i * i * i))
		if k != -i {
			t.Logf("intgr.Cbrt(%X*%X*%X) == %X\n", -i, -i, -i, k)
			t.Fail()
		}
	}
	for i := uMax; i > 0; i >>= 1 {
		k := uintgr.Cbrt(i * i * i)
		if k != i {
			t.Logf("uintgr.Cbrt(%X*%X*%X) == %X\n", i, i, i, k)
			t.Fail()
		}
	}
	for i := i32Max; i > 0; i >>= 1 {
		k := i32.Cbrt(i * i * i)
		if k != i {
			t.Logf("i32.Cbrt(%X*%X*%X) == %X\n", i, i, i, k)
			t.Fail()
		}
		k = i32.Cbrt(-(i * i * i))
		if k != -i {
			t.Logf("i32.Cbrt(%X*%X*%X) == %X\n", -i, -i, -i, k)
			t.Fail()
		}
	}
	for i := u32Max; i > 0; i >>= 1 {
		k := u32.Cbrt(i * i * i)
		if k != i {
			t.Logf("u32.Cbrt(%X*%X*%X) == %X\n", i, i, i, k)
			t.Fail()
		}
	}
	for i := i64Max; i > 0; i >>= 1 {
		k := i64.Cbrt(i * i * i)
		if k != i {
			t.Logf("i64.Cbrt(%X*%X*%X) == %X\n", i, i, i, k)
			t.Fail()
		}
		k = i64.Cbrt(-(i * i * i))
		if k != -i {
			t.Logf("i64.Cbrt(%X*%X*%X) == %X\n", -i, -i, -i, k)
			t.Fail()
		}
	}
	for i := u64Max; i > 0; i >>= 1 {
		k := u64.Cbrt(i * i * i)
		if k != i {
			t.Logf("u64.Cbrt(%X*%X*%X) == %X\n", i, i, i, k)
			t.Fail()
		}
	}
}