-
Notifications
You must be signed in to change notification settings - Fork 1k
[Move] Part-2 Classes into Different Library - Neo.IO
#3388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shargon
merged 12 commits into
neo-project:master
from
cschuchardt88:rebuild/the-split-2
Jul 16, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bf93412
Part-1 `Neo.IO` - move
cschuchardt88 4d08154
Part-2
cschuchardt88 597c9ca
Merge branch 'master' into rebuild/the-split-2
cschuchardt88 9881579
Added `BigInteger` to `Neo.Extensions`
cschuchardt88 8779151
Found more `BigInteger`
cschuchardt88 dbbf5b3
Merge branch 'master' into rebuild/the-split-2
shargon b64435b
Added Tests
cschuchardt88 583e610
Merge branch 'rebuild/the-split-2' of https://github.com/cschuchardt8…
cschuchardt88 4a789e4
Merge branch 'master' into rebuild/the-split-2
cschuchardt88 5f9164b
Merge branch 'master' into rebuild/the-split-2
d994cdc
Merge branch 'master' into rebuild/the-split-2
shargon ee7e3ca
Update tests/Neo.Extensions.Tests/UT_BigIntegerExtensions.cs
shargon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,91 @@ | ||
| // Copyright (C) 2015-2024 The Neo Project. | ||
| // | ||
| // BigIntegerExtensions.cs file belongs to the neo project and is free | ||
| // software distributed under the MIT software license, see the | ||
| // accompanying file LICENSE in the main directory of the | ||
| // repository or http://www.opensource.org/licenses/mit-license.php | ||
| // for more details. | ||
| // | ||
| // Redistribution and use in source and binary forms with or without | ||
| // modifications are permitted. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Numerics; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| namespace Neo.Extensions | ||
| { | ||
| public static class BigIntegerExtensions | ||
| { | ||
| public static int GetLowestSetBit(this BigInteger i) | ||
| { | ||
| if (i.Sign == 0) | ||
| return -1; | ||
| var b = i.ToByteArray(); | ||
| var w = 0; | ||
| while (b[w] == 0) | ||
| w++; | ||
| for (var x = 0; x < 8; x++) | ||
| if ((b[w] & 1 << x) > 0) | ||
| return x + w * 8; | ||
| throw new Exception(); | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static BigInteger Mod(this BigInteger x, BigInteger y) | ||
| { | ||
| x %= y; | ||
| if (x.Sign < 0) | ||
| x += y; | ||
| return x; | ||
| } | ||
|
|
||
| public static BigInteger ModInverse(this BigInteger a, BigInteger n) | ||
| { | ||
| BigInteger i = n, v = 0, d = 1; | ||
| while (a > 0) | ||
| { | ||
| BigInteger t = i / a, x = a; | ||
| a = i % x; | ||
| i = x; | ||
| x = d; | ||
| d = v - t * x; | ||
| v = x; | ||
| } | ||
| v %= n; | ||
| if (v < 0) v = (v + n) % n; | ||
| return v; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static bool TestBit(this BigInteger i, int index) | ||
| { | ||
| return (i & (BigInteger.One << index)) > BigInteger.Zero; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Finds the sum of the specified integers. | ||
| /// </summary> | ||
| /// <param name="source">The specified integers.</param> | ||
| /// <returns>The sum of the integers.</returns> | ||
| public static BigInteger Sum(this IEnumerable<BigInteger> source) | ||
| { | ||
| var sum = BigInteger.Zero; | ||
| foreach (var bi in source) sum += bi; | ||
| return sum; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts a <see cref="BigInteger"/> to byte array and eliminates all the leading zeros. | ||
| /// </summary> | ||
| /// <param name="i">The <see cref="BigInteger"/> to convert.</param> | ||
| /// <returns>The converted byte array.</returns> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static byte[] ToByteArrayStandard(this BigInteger i) | ||
| { | ||
| if (i.IsZero) return Array.Empty<byte>(); | ||
| return i.ToByteArray(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.