Source File
bits.go
Belonging Package
modernc.org/mathutil
// Copyright (c) 2014 The mathutil Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package mathutil // import "modernc.org/mathutil"import ()// BitLenByte returns the bit width of the non zero part of n.func ( byte) int {return log2[] + 1}// BitLenUint16 returns the bit width of the non zero part of n.func ( uint16) int {if := >> 8; != 0 {return log2[] + 8 + 1}return log2[] + 1}// BitLenUint32 returns the bit width of the non zero part of n.func ( uint32) int {if := >> 24; != 0 {return log2[] + 24 + 1}if := >> 16; != 0 {return log2[] + 16 + 1}if := >> 8; != 0 {return log2[] + 8 + 1}return log2[] + 1}// BitLen returns the bit width of the non zero part of n.func ( int) int { // Should handle correctly [future] 64 bit Go intsif IntBits == 64 {return BitLenUint64(uint64())}if := byte( >> 24); != 0 {return log2[] + 24 + 1}if := byte( >> 16); != 0 {return log2[] + 16 + 1}if := byte( >> 8); != 0 {return log2[] + 8 + 1}return log2[byte()] + 1}// BitLenUint returns the bit width of the non zero part of n.func ( uint) int { // Should handle correctly [future] 64 bit Go uintsif IntBits == 64 {return BitLenUint64(uint64())}if := >> 24; != 0 {return log2[] + 24 + 1}if := >> 16; != 0 {return log2[] + 16 + 1}if := >> 8; != 0 {return log2[] + 8 + 1}return log2[] + 1}// BitLenUint64 returns the bit width of the non zero part of n.func ( uint64) int {if := >> 56; != 0 {return log2[] + 56 + 1}if := >> 48; != 0 {return log2[] + 48 + 1}if := >> 40; != 0 {return log2[] + 40 + 1}if := >> 32; != 0 {return log2[] + 32 + 1}if := >> 24; != 0 {return log2[] + 24 + 1}if := >> 16; != 0 {return log2[] + 16 + 1}if := >> 8; != 0 {return log2[] + 8 + 1}return log2[] + 1}// BitLenUintptr returns the bit width of the non zero part of n.func ( uintptr) int {if := >> 56; != 0 {return log2[] + 56 + 1}if := >> 48; != 0 {return log2[] + 48 + 1}if := >> 40; != 0 {return log2[] + 40 + 1}if := >> 32; != 0 {return log2[] + 32 + 1}if := >> 24; != 0 {return log2[] + 24 + 1}if := >> 16; != 0 {return log2[] + 16 + 1}if := >> 8; != 0 {return log2[] + 8 + 1}return log2[] + 1}// PopCountByte returns population count of n (number of bits set in n).func ( byte) int {return int(popcnt[])}// PopCountUint16 returns population count of n (number of bits set in n).func ( uint16) int {return int(popcnt[byte(>>8)]) + int(popcnt[byte()])}// PopCountUint32 returns population count of n (number of bits set in n).func ( uint32) int {return int(popcnt[byte(>>24)]) + int(popcnt[byte(>>16)]) +int(popcnt[byte(>>8)]) + int(popcnt[byte()])}// PopCount returns population count of n (number of bits set in n).func ( int) int { // Should handle correctly [future] 64 bit Go intsif IntBits == 64 {return PopCountUint64(uint64())}return PopCountUint32(uint32())}// PopCountUint returns population count of n (number of bits set in n).func ( uint) int { // Should handle correctly [future] 64 bit Go uintsif IntBits == 64 {return PopCountUint64(uint64())}return PopCountUint32(uint32())}// PopCountUintptr returns population count of n (number of bits set in n).func ( uintptr) int {if UintPtrBits == 64 {return PopCountUint64(uint64())}return PopCountUint32(uint32())}// PopCountUint64 returns population count of n (number of bits set in n).func ( uint64) int {return int(popcnt[byte(>>56)]) + int(popcnt[byte(>>48)]) +int(popcnt[byte(>>40)]) + int(popcnt[byte(>>32)]) +int(popcnt[byte(>>24)]) + int(popcnt[byte(>>16)]) +int(popcnt[byte(>>8)]) + int(popcnt[byte()])}// PopCountBigInt returns population count of |n| (number of bits set in |n|).func ( *big.Int) ( int) {for , := range .Bits() {+= PopCountUintptr(uintptr())}return}
![]() |
The pages are generated with Golds v0.3.6. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |