-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 67c53f8
Showing
5 changed files
with
1,109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 duggavo | ||
Portions copyright (c) 2019 Luke Champine | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# uint128 | ||
|
||
[](https://godoc.org/github.com/duggavo/uint128) | ||
[](https://goreportcard.com/report/github.com/duggavo/uint128) | ||
|
||
``` | ||
go get github.com/duggavo/uint128 | ||
``` | ||
|
||
`uint128` provides a high-performance `Uint128` type that supports standard arithmetic | ||
operations and JSON/textual marshalling. Unlike `math/big`, operations on `Uint128` | ||
values always produce new values instead of modifying a pointer receiver. | ||
|
||
The name `uint128.Uint128` stutters, so I recommend either using a "dot import" | ||
or aliasing `uint128.Uint128` to give it a project-specific name. | ||
|
||
## Benchmarks | ||
|
||
Addition, multiplication, and subtraction are on par with their native 64-bit | ||
equivalents. Division is slower: ~20x slower when dividing a `Uint128` by a | ||
`uint64`, and ~100x slower when dividing by a `Uint128`. However, division is | ||
still faster than with `big.Int` (for the same operands), especially when | ||
dividing by a `uint64`. | ||
|
||
``` | ||
BenchmarkArithmetic/Add-4 2000000000 0.45 ns/op 0 B/op 0 allocs/op | ||
BenchmarkArithmetic/Sub-4 2000000000 0.67 ns/op 0 B/op 0 allocs/op | ||
BenchmarkArithmetic/Mul-4 2000000000 0.42 ns/op 0 B/op 0 allocs/op | ||
BenchmarkArithmetic/Lsh-4 2000000000 1.06 ns/op 0 B/op 0 allocs/op | ||
BenchmarkArithmetic/Rsh-4 2000000000 1.06 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDivision/native_64/64-4 2000000000 0.39 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDivision/Div_128/64-4 2000000000 6.28 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDivision/Div_128/128-4 30000000 45.2 ns/op 0 B/op 0 allocs/op | ||
BenchmarkDivision/big.Int_128/64-4 20000000 98.2 ns/op 8 B/op 1 allocs/op | ||
BenchmarkDivision/big.Int_128/128-4 30000000 53.4 ns/op 48 B/op 1 allocs/op | ||
BenchmarkString/Uint128-4 10000000 173 ns/op 48 B/op 1 allocs/op | ||
BenchmarkString/big.Int-4 5000000 350 ns/op 144 B/op 3 allocs/op | ||
``` | ||
|
||
## License | ||
This package is licensed under MIT. See the LICENSE.txt file for more information. | ||
|
||
Copyright (c) 2024 duggavo | ||
|
||
Portions Copyright (c) 2019 Luke Champine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/duggavo/uint128 | ||
|
||
go 1.20 |
Oops, something went wrong.