bits.Mul() Golang中的函數用於查找x和y的full-width乘積。該函數的執行時間不取決於輸入。要訪問此函數,需要在程序中導入math /bits程序包。
用法:
func Mul(x, y uint) (hi, lo uint)
參數:此函數采用uint類型的兩個參數,即x,y。
Note:(hi,lo)= x * y
在這裏,hi是乘積位的上半部分,lo是返回的下半部分。
返回值:此函數返回x和y的full-width乘積。
範例1:
// Golang program to illustrate
// bits.Mul() Function
package main
import (
"fmt"
"math/bits"
)
// Main function
func main() {
// Using Mul() function
hi, lo:= bits.Mul(5, 10)
fmt.Println("Full-width product of x and y:", hi, lo)
}
輸出:
Full-width product of x and y: 0 50
範例2:
// Golang program to illustrate
// bits.Mul() Function
package main
import (
"fmt"
"math/bits"
)
// Main function
func main() {
// Using Mul() function
const a, b = 34, 56
hi, lo := bits.Mul(a, b)
fmt.Println("Number 1:", a)
fmt.Println("Number 2:", b)
fmt.Println("Upper half:", hi)
fmt.Println("Lower half:", lo)
}
輸出:
Number 1:34 Number 2:56 Upper half:0 Lower half:1904
相關用法
- Golang math.Lgamma()用法及代碼示例
- Golang math.Float64bits()用法及代碼示例
- Golang atomic.AddInt64()用法及代碼示例
- Golang atomic.StoreInt64()用法及代碼示例
- Golang reflect.FieldByIndex()用法及代碼示例
- Golang string.Contains用法及代碼示例
- Golang bits.Sub()用法及代碼示例
- Golang io.PipeWriter.CloseWithError()用法及代碼示例
- Golang time.Round()用法及代碼示例
- Golang reflect.AppendSlice()用法及代碼示例
- Golang reflect.ChanOf()用法及代碼示例
- Golang flag.Bool()用法及代碼示例
- Golang time.Sleep()用法及代碼示例
- Golang time.Time.Year()用法及代碼示例
- Golang reflect.DeepEqual()用法及代碼示例
- Golang reflect.Indirect()用法及代碼示例
- Golang reflect.CanAddr()用法及代碼示例
- Golang reflect.CanInterface()用法及代碼示例
- Golang reflect.CanSet()用法及代碼示例
- Golang reflect.Cap()用法及代碼示例
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 bits.Mul() Function in Golang with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。