Documentation
¶
Overview ¶
The package int128 provides 128-bit integer types.
Index ¶
- type Int128
- func (a Int128) Add(b Int128) Int128
- func (a Int128) And(b Int128) Int128
- func (a Int128) AndNot(b Int128) Int128
- func (a Int128) Append(dst []byte, base int) []byte
- func (a Int128) Cmp(b Int128) int
- func (a Int128) Div(b Int128) Int128
- func (a Int128) DivMod(b Int128) (Int128, Int128)
- func (a Int128) Format(s fmt.State, verb rune)
- func (a Int128) Lsh(i uint) Int128
- func (a Int128) MarshalJSON() ([]byte, error)
- func (a Int128) MarshalText() ([]byte, error)
- func (a Int128) Mod(b Int128) Int128
- func (a Int128) Mul(b Int128) Int128
- func (a Int128) Neg() Int128
- func (a Int128) Not() Int128
- func (a Int128) Or(b Int128) Int128
- func (a Int128) Quo(b Int128) Int128
- func (a Int128) QuoRem(b Int128) (Int128, Int128)
- func (a Int128) Rem(b Int128) Int128
- func (a Int128) Rsh(i uint) Int128
- func (a Int128) String() string
- func (a Int128) Sub(b Int128) Int128
- func (a Int128) Text(base int) string
- func (a Int128) Uint128() Uint128
- func (a Int128) Xor(b Int128) Int128
- type Uint128
- func (a Uint128) Add(b Uint128) Uint128
- func (a Uint128) And(b Uint128) Uint128
- func (a Uint128) AndNot(b Uint128) Uint128
- func (a Uint128) Append(dst []byte, base int) []byte
- func (a Uint128) Cmp(b Uint128) int
- func (a Uint128) Div(b Uint128) Uint128
- func (a Uint128) DivMod(b Uint128) (Uint128, Uint128)
- func (a Uint128) Format(s fmt.State, ch rune)
- func (a Uint128) Int128() Int128
- func (a Uint128) LeadingZeros() int
- func (a Uint128) Len() int
- func (a Uint128) Lsh(i uint) Uint128
- func (a Uint128) MarshalJSON() ([]byte, error)
- func (a Uint128) MarshalText() ([]byte, error)
- func (a Uint128) Mod(b Uint128) Uint128
- func (a Uint128) Mul(b Uint128) Uint128
- func (a Uint128) Neg() Uint128
- func (a Uint128) Not() Uint128
- func (a Uint128) OnesCount() int
- func (a Uint128) Or(b Uint128) Uint128
- func (a Uint128) Quo(b Uint128) Uint128
- func (a Uint128) QuoRem(b Uint128) (Uint128, Uint128)
- func (a Uint128) Rem(b Uint128) Uint128
- func (a Uint128) Reverse() Uint128
- func (a Uint128) ReverseBytes() Uint128
- func (a Uint128) RotateLeft(k int) Uint128
- func (a Uint128) Rsh(i uint) Uint128
- func (a Uint128) String() string
- func (a Uint128) Sub(b Uint128) Uint128
- func (a Uint128) Text(base int) string
- func (a Uint128) TrailingZeros() int
- func (a Uint128) Xor(b Uint128) Uint128
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Int128 ¶
Int128 is a signed 128-bit integer.
func Float64ToInt128 ¶
Float64ToUint128 returns the nearest Uint128 representation of v.
func (Int128) Add ¶
Add returns the sum a+b.
This function's execution time does not depend on the inputs.
Example ¶
package main
import (
"fmt"
"github.com/shogo82148/int128"
)
func main() {
a := int128.Int128{0, 1} // = 1
b := int128.Int128{0, 2} // = 2
c := a.Add(b)
fmt.Println(c)
}
Output: 3
func (Int128) And ¶
And returns the bitwise AND a&b.
This function's execution time does not depend on the inputs.
func (Int128) AndNot ¶
AndNot returns the bitwise AND NOT a&^b.
This function's execution time does not depend on the inputs.
func (Int128) Append ¶
Append appends the string representation of a, as generated by a.Text(base), to buf and returns the extended buffer.
func (Int128) Div ¶
Div returns the quotient a/b for b != 0. If b == 0, a division-by-zero run-time panic occurs.
func (Int128) DivMod ¶
DivMod returns the quotient and remainder of a/b for b != 0. If b == 0, a division-by-zero run-time panic occurs.
DivMod implements Euclidean division and modulus (unlike Go):
q = a div b such that m = a - b*q with 0 <= m < |y|
func (Int128) Format ¶ added in v0.2.0
Format implements fmt.Formatter.
func (Int128) Lsh ¶
Lsh returns the logical left shift a<<i.
This function's execution time does not depend on the inputs.
func (Int128) MarshalJSON ¶
func (Int128) MarshalText ¶
func (Int128) Mod ¶
Mod returns the modulus x%y for y != 0. If y == 0, a division-by-zero run-time panic occurs.
func (Int128) Mul ¶
Mul returns the product x*y.
Example ¶
package main
import (
"fmt"
"github.com/shogo82148/int128"
)
func main() {
a := int128.Int128{0, 1} // = 1
b := int128.Int128{0, 2} // = 2
c := a.Mul(b)
fmt.Println(c)
}
Output: 2
func (Int128) Neg ¶
Neg returns the negation -a.
This function's execution time does not depend on the inputs.
func (Int128) Not ¶
Not returns the bitwise NOT ^a.
This function's execution time does not depend on the inputs.
func (Int128) Or ¶
Or returns the bitwise OR a|b.
This function's execution time does not depend on the inputs.
func (Int128) Quo ¶
Quo returns the quotient a/b for b != 0. If b == 0, a division-by-zero run-time panic occurs. Quo implements truncated division (like Go); see QuoRem for more details.
func (Int128) QuoRem ¶
QuoRem returns the quotient a/b and the remainder a%b for b != 0. a division-by-zero run-time panic occurs.
QuoRem implements T-division and modulus (like Go):
q = a/b with the result truncated to zero r = a - b*q
func (Int128) Rem ¶
Rem returns he remainder a%b for b != 0. If b == 0, a division-by-zero run-time panic occurs. Rem implements truncated modulus (like Go); see QuoRem for more details.
func (Int128) Rsh ¶
Rsh returns the logical right shift a>>i.
This function's execution time does not depend on the inputs.
func (Int128) Sub ¶
Sub returns the difference x-y.
This function's execution time does not depend on the inputs.
Example ¶
package main
import (
"fmt"
"github.com/shogo82148/int128"
)
func main() {
a := int128.Int128{0, 1} // = 1
b := int128.Int128{0, 2} // = 2
c := a.Sub(b)
fmt.Println(c)
}
Output: -1
func (Int128) Text ¶
Text returns the string representation of a in the given base. Base must be between 2 and 62, inclusive. The result uses the lower-case letters 'a' to 'z' for digit values 10 to 35, and the upper-case letters 'A' to 'Z' for digit values 36 to 61. No prefix (such as "0x") is added to the string.
type Uint128 ¶
Uint128 is a 128-bit unsigned integer.
func Float64ToUint128 ¶
Float64ToUint128 returns the nearest Uint128 representation of v.
func (Uint128) Add ¶
Add returns the sum a+b.
This function's execution time does not depend on the inputs.
Example ¶
package main
import (
"fmt"
"github.com/shogo82148/int128"
)
func main() {
a := int128.Uint128{0, 1} // = 1
b := int128.Uint128{0, 2} // = 2
c := a.Add(b)
fmt.Println(c)
}
Output: 3
func (Uint128) And ¶
And returns the bitwise AND a&b.
This function's execution time does not depend on the inputs.
func (Uint128) AndNot ¶
AndNot returns the bitwise AND NOT a&^b.
This function's execution time does not depend on the inputs.
func (Uint128) Append ¶
Append appends the string representation of a, as generated by a.Text(base), to buf and returns the extended buffer.
func (Uint128) Div ¶
Div returns the quotient a/b for b != 0. If b == 0, a division-by-zero run-time panic occurs.
func (Uint128) DivMod ¶
DivMod returns the quotient and remainder of a/b for b != 0. If b == 0, a division-by-zero run-time panic occurs.
q = a div b such that m = a - b*q with 0 <= m < |y|
func (Uint128) Format ¶ added in v0.2.0
Format implements fmt.Formatter.
func (Uint128) LeadingZeros ¶
LeadingZeros returns the number of leading zero bits in a; the result is 128 for a == 0.
func (Uint128) Len ¶
Len returns the minimum number of bits required to represent a; the result is 0 for a == 0.
func (Uint128) Lsh ¶
Lsh returns the logical left shift a<<i.
This function's execution time does not depend on the inputs.
func (Uint128) MarshalJSON ¶
func (Uint128) MarshalText ¶
func (Uint128) Mod ¶
Mod returns the modulus x%y for y != 0. If y == 0, a division-by-zero run-time panic occurs.
func (Uint128) Mul ¶
Mul returns the product x*y.
This function's execution time does not depend on the inputs.
func (Uint128) Neg ¶
Neg returns the negation -a.
This function's execution time does not depend on the inputs.
func (Uint128) Not ¶
Not returns the bitwise NOT ^a.
This function's execution time does not depend on the inputs.
func (Uint128) Or ¶
Or returns the bitwise OR a|b.
This function's execution time does not depend on the inputs.
func (Uint128) Quo ¶
Quo returns the quotient a/b for b != 0. If b == 0, a division-by-zero run-time panic occurs. Quo is the same as Div in Uint128.
func (Uint128) QuoRem ¶
QuoRem returns the quotient a/b and the remainder a%b for b != 0. a division-by-zero run-time panic occurs.
q = a/b with the result truncated to zero r = a - b*q
QuoRem is the same as DivMod in Uint128.
func (Uint128) Rem ¶
Rem returns he remainder a%b for b != 0. If b == 0, a division-by-zero run-time panic occurs. Rem is the same as Mod in Uint128.
func (Uint128) ReverseBytes ¶
ReverseBytes returns the value of a with its bytes in reversed order.
This function's execution time does not depend on the inputs.
func (Uint128) RotateLeft ¶
RotateLeft returns the value of a rotated left by (k mod 128) bits.
This function's execution time does not depend on the inputs.
func (Uint128) Rsh ¶
Rsh returns the logical right shift a>>i.
This function's execution time does not depend on the inputs.
func (Uint128) Sub ¶
Sub returns the difference x-y.
This function's execution time does not depend on the inputs.
Example ¶
package main
import (
"fmt"
"github.com/shogo82148/int128"
)
func main() {
a := int128.Uint128{0, 3} // = 3
b := int128.Uint128{0, 2} // = 2
c := a.Sub(b)
fmt.Println(c)
}
Output: 1
func (Uint128) Text ¶
Text returns the string representation of a in the given base. Base must be between 2 and 62, inclusive. The result uses the lower-case letters 'a' to 'z' for digit values 10 to 35, and the upper-case letters 'A' to 'Z' for digit values 36 to 61. No prefix (such as "0x") is added to the string.
func (Uint128) TrailingZeros ¶
TrailingZeros returns the number of trailing zero bits in a; the result is 128 for a == 0.