diff --git a/apiCount.include.md b/apiCount.include.md index 78c0456c..d55fa0b9 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -1,28 +1,28 @@ -**API count: 1055** +**API count: 1067** ### Per Target Framework | Target | APIs | | -- | -- | -| `net461` | 991 | -| `net462` | 991 | -| `net47` | 990 | -| `net471` | 989 | -| `net472` | 985 | -| `net48` | 985 | -| `net481` | 985 | -| `netstandard2.0` | 987 | -| `netstandard2.1` | 840 | -| `netcoreapp2.0` | 910 | -| `netcoreapp2.1` | 851 | -| `netcoreapp2.2` | 851 | -| `netcoreapp3.0` | 806 | -| `netcoreapp3.1` | 805 | -| `net5.0` | 677 | -| `net6.0` | 578 | -| `net7.0` | 423 | -| `net8.0` | 304 | -| `net9.0` | 210 | -| `net10.0` | 156 | +| `net461` | 1004 | +| `net462` | 1004 | +| `net47` | 1003 | +| `net471` | 1002 | +| `net472` | 998 | +| `net48` | 998 | +| `net481` | 998 | +| `netstandard2.0` | 1000 | +| `netstandard2.1` | 853 | +| `netcoreapp2.0` | 923 | +| `netcoreapp2.1` | 864 | +| `netcoreapp2.2` | 864 | +| `netcoreapp3.0` | 819 | +| `netcoreapp3.1` | 818 | +| `net5.0` | 690 | +| `net6.0` | 591 | +| `net7.0` | 438 | +| `net8.0` | 317 | +| `net9.0` | 223 | +| `net10.0` | 169 | | `net11.0` | 58 | -| `uap10.0` | 977 | +| `uap10.0` | 990 | diff --git a/api_list.include.md b/api_list.include.md index af4bcdee..60175649 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -99,6 +99,7 @@ * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryformat?view=net-11.0#system-byte-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryformat?view=net-11.0#system-byte-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `byte Log10(byte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, byte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse?view=net-11.0#system-byte-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-byte@)) * `bool TryParse(ReadOnlySpan, IFormatProvider?, byte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse?view=net-11.0#system-byte-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-byte@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, byte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse?view=net-11.0#system-byte-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-byte@)) @@ -582,10 +583,16 @@ * `ReadOnlyCollection AsReadOnly()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.collectionextensions.asreadonly?view=net-11.0#system-collections-generic-collectionextensions-asreadonly-1(system-collections-generic-ilist((-0)))) +#### Int128 + + * `Int128 Log10(Int128)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int128.log10?view=net-11.0) + + #### Int16 * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryformat?view=net-11.0#system-int16-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryformat?view=net-11.0#system-int16-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `short Log10(short)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, short)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryparse?view=net-11.0#system-int16-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-int16@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, short)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryparse?view=net-11.0#system-int16-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-int16@)) * `bool TryParse(ReadOnlySpan, short)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryparse?view=net-11.0#system-int16-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-int16@)) @@ -600,6 +607,7 @@ * `float Int32BitsToSingle(int)` * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryformat?view=net-11.0#system-int32-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryformat?view=net-11.0#system-int32-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `int Log10(int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=net-11.0#system-int32-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-int32@)) * `bool TryParse(ReadOnlySpan, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=net-11.0#system-int32-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-int32@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=net-11.0#system-int32-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-int32@)) @@ -613,6 +621,7 @@ * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryformat?view=net-11.0#system-int64-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryformat?view=net-11.0#system-int64-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `long Log10(long)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, long)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse?view=net-11.0#system-int64-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-int64@)) * `bool TryParse(ReadOnlySpan, long)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse?view=net-11.0#system-int64-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-int64@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, long)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse?view=net-11.0#system-int64-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-int64@)) @@ -628,6 +637,7 @@ #### IntPtr + * `nint Log10(nint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.intptr.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, nint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.intptr.tryparse?view=net-11.0#system-intptr-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-intptr@)) * `bool TryParse(ReadOnlySpan, nint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.intptr.tryparse?view=net-11.0#system-intptr-tryparse(system-readonlyspan((system-byte))-system-intptr@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, nint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.intptr.tryparse?view=net-11.0#system-intptr-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-intptr@)) @@ -986,6 +996,7 @@ * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryformat?view=net-11.0#system-sbyte-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryformat?view=net-11.0#system-sbyte-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `sbyte Log10(sbyte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, sbyte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryparse?view=net-11.0#system-sbyte-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-sbyte@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, sbyte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryparse?view=net-11.0#system-sbyte-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-sbyte@)) * `bool TryParse(ReadOnlySpan, sbyte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryparse?view=net-11.0#system-sbyte-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-sbyte@)) @@ -1321,10 +1332,16 @@ * `ValueTask SendAsync(ReadOnlyMemory, string?, int, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.sendasync?view=net-11.0#system-net-sockets-udpclient-sendasync(system-readonlymemory((system-byte))-system-string-system-int32-system-threading-cancellationtoken)) +#### UInt128 + + * `UInt128 Log10(UInt128)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint128.log10?view=net-11.0) + + #### UInt16 * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryformat?view=net-11.0#system-uint16-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryformat?view=net-11.0#system-uint16-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `ushort Log10(ushort)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, ushort)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryparse?view=net-11.0#system-uint16-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-uint16@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, ushort)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryparse?view=net-11.0#system-uint16-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-uint16@)) * `bool TryParse(ReadOnlySpan, ushort)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryparse?view=net-11.0#system-uint16-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-uint16@)) @@ -1339,6 +1356,7 @@ * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryformat?view=net-11.0#system-uint32-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryformat?view=net-11.0#system-uint32-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `float UInt32BitsToSingle(uint)` + * `uint Log10(uint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, uint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryparse?view=net-11.0#system-uint32-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-uint32@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, uint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryparse?view=net-11.0#system-uint32-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-uint32@)) * `bool TryParse(ReadOnlySpan, uint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryparse?view=net-11.0#system-uint32-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-uint32@)) @@ -1353,6 +1371,7 @@ * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryformat?view=net-11.0#system-uint64-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryformat?view=net-11.0#system-uint64-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `double UInt64BitsToDouble(ulong)` + * `ulong Log10(ulong)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, ulong)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryparse?view=net-11.0#system-uint64-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-uint64@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, ulong)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryparse?view=net-11.0#system-uint64-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-uint64@)) * `bool TryParse(ReadOnlySpan, ulong)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryparse?view=net-11.0#system-uint64-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-uint64@)) @@ -1364,6 +1383,7 @@ #### UIntPtr + * `nuint Log10(nuint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uintptr.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, nuint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uintptr.tryparse?view=net-11.0#system-uintptr-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-uintptr@)) * `bool TryParse(ReadOnlySpan, nuint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uintptr.tryparse?view=net-11.0#system-uintptr-tryparse(system-readonlyspan((system-byte))-system-uintptr@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, nuint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uintptr.tryparse?view=net-11.0#system-uintptr-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-uintptr@)) diff --git a/assemblySize.include.md b/assemblySize.include.md index 32512eea..3c78ef83 100644 --- a/assemblySize.include.md +++ b/assemblySize.include.md @@ -2,26 +2,26 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 364.0KB | +356.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| netstandard2.1 | 8.5KB | 318.0KB | +309.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net461 | 8.5KB | 362.5KB | +354.0KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | -| net462 | 7.0KB | 366.0KB | +359.0KB | +9.5KB | +7.0KB | +9.5KB | +14.0KB | -| net47 | 7.0KB | 366.0KB | +359.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 365.0KB | +356.5KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | -| net472 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| net48 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| net481 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| netcoreapp2.0 | 9.0KB | 341.5KB | +332.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 321.5KB | +312.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.2 | 9.0KB | 321.5KB | +312.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.0 | 9.5KB | 315.5KB | +306.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.1 | 9.5KB | 314.0KB | +304.5KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | -| net5.0 | 9.5KB | 278.0KB | +268.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net6.0 | 10.0KB | 219.5KB | +209.5KB | +9.5KB | +6.5KB | +512bytes | +3.0KB | -| net7.0 | 10.0KB | 181.0KB | +171.0KB | +12.0KB | +8.5KB | +512bytes | +3.5KB | -| net8.0 | 9.5KB | 152.0KB | +142.5KB | +8.5KB | | +512bytes | +3.0KB | -| net9.0 | 9.5KB | 105.0KB | +95.5KB | +8.5KB | | +512bytes | +3.5KB | -| net10.0 | 10.0KB | 82.5KB | +72.5KB | +8.5KB | | +512bytes | +3.5KB | +| netstandard2.0 | 8.0KB | 365.5KB | +357.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| netstandard2.1 | 8.5KB | 319.5KB | +311.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net461 | 8.5KB | 364.5KB | +356.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net462 | 7.0KB | 368.0KB | +361.0KB | +7.5KB | +6.5KB | +9.0KB | +13.5KB | +| net47 | 7.0KB | 367.5KB | +360.5KB | +7.5KB | +6.5KB | +9.5KB | +14.0KB | +| net471 | 8.5KB | 365.5KB | +357.0KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | +| net472 | 8.5KB | 365.5KB | +357.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net48 | 8.5KB | 365.5KB | +357.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net481 | 8.5KB | 365.5KB | +357.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| netcoreapp2.0 | 9.0KB | 343.0KB | +334.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.1 | 9.0KB | 323.0KB | +314.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.2 | 9.0KB | 323.0KB | +314.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp3.0 | 9.5KB | 317.0KB | +307.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp3.1 | 9.5KB | 315.5KB | +306.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net5.0 | 9.5KB | 279.5KB | +270.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net6.0 | 10.0KB | 221.0KB | +211.0KB | +10.0KB | +7.0KB | +512bytes | +3.5KB | +| net7.0 | 10.0KB | 183.5KB | +173.5KB | +12.0KB | +8.5KB | +3.5KB | +6.0KB | +| net8.0 | 9.5KB | 156.5KB | +147.0KB | +8.5KB | | +512bytes | +3.5KB | +| net9.0 | 9.5KB | 109.5KB | +100.0KB | +8.5KB | | +512bytes | +3.5KB | +| net10.0 | 10.0KB | 87.5KB | +77.5KB | +8.5KB | | +512bytes | +3.0KB | | net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.5KB | +512bytes | +1.0KB | +4.0KB | @@ -29,24 +29,24 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 534.0KB | +526.0KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| netstandard2.1 | 8.5KB | 461.4KB | +452.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net461 | 8.5KB | 533.6KB | +525.1KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | -| net462 | 7.0KB | 537.1KB | +530.1KB | +17.2KB | +8.7KB | +14.4KB | +19.4KB | -| net47 | 7.0KB | 536.8KB | +529.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 535.5KB | +527.0KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | -| net472 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| net48 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| net481 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| netcoreapp2.0 | 9.0KB | 501.0KB | +492.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 468.6KB | +459.6KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.2 | 9.0KB | 468.6KB | +459.6KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.0 | 9.5KB | 454.5KB | +445.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.1 | 9.5KB | 453.0KB | +443.5KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | -| net5.0 | 9.5KB | 398.9KB | +389.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net6.0 | 10.0KB | 320.4KB | +310.4KB | +17.2KB | +8.2KB | +1.1KB | +3.7KB | -| net7.0 | 10.0KB | 263.1KB | +253.1KB | +19.6KB | +9.9KB | +1.1KB | +4.2KB | -| net8.0 | 9.5KB | 218.7KB | +209.2KB | +16.0KB | +299bytes | +1.1KB | +3.7KB | -| net9.0 | 9.5KB | 150.6KB | +141.1KB | +16.0KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 119.4KB | +109.4KB | +16.0KB | | +1.1KB | +4.2KB | +| netstandard2.0 | 8.0KB | 536.9KB | +528.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| netstandard2.1 | 8.5KB | 464.3KB | +455.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net461 | 8.5KB | 536.9KB | +528.4KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net462 | 7.0KB | 540.4KB | +533.4KB | +15.2KB | +8.2KB | +13.9KB | +18.9KB | +| net47 | 7.0KB | 539.7KB | +532.7KB | +15.2KB | +8.2KB | +14.4KB | +19.4KB | +| net471 | 8.5KB | 537.3KB | +528.8KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | +| net472 | 8.5KB | 536.2KB | +527.7KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net48 | 8.5KB | 536.2KB | +527.7KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net481 | 8.5KB | 536.2KB | +527.7KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| netcoreapp2.0 | 9.0KB | 503.8KB | +494.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.1 | 9.0KB | 471.5KB | +462.5KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.2 | 9.0KB | 471.5KB | +462.5KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp3.0 | 9.5KB | 457.4KB | +447.9KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp3.1 | 9.5KB | 455.9KB | +446.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net5.0 | 9.5KB | 401.8KB | +392.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net6.0 | 10.0KB | 323.3KB | +313.3KB | +17.7KB | +8.7KB | +1.1KB | +4.2KB | +| net7.0 | 10.0KB | 267.5KB | +257.5KB | +19.6KB | +9.9KB | +4.1KB | +6.7KB | +| net8.0 | 9.5KB | 226.7KB | +217.2KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | +| net9.0 | 9.5KB | 158.5KB | +149.0KB | +16.0KB | | +1.1KB | +4.2KB | +| net10.0 | 10.0KB | 127.8KB | +117.8KB | +16.0KB | | +1.1KB | +3.7KB | | net11.0 | 10.0KB | 30.4KB | +20.4KB | +17.0KB | +512bytes | +1.6KB | +4.7KB | diff --git a/readme.md b/readme.md index 6246fc37..63bfec57 100644 --- a/readme.md +++ b/readme.md @@ -13,34 +13,34 @@ The package targets `netstandard2.0` and is designed to support the following ru * `uap10` -**API count: 1055** +**API count: 1067** ### Per Target Framework | Target | APIs | | -- | -- | -| `net461` | 991 | -| `net462` | 991 | -| `net47` | 990 | -| `net471` | 989 | -| `net472` | 985 | -| `net48` | 985 | -| `net481` | 985 | -| `netstandard2.0` | 987 | -| `netstandard2.1` | 840 | -| `netcoreapp2.0` | 910 | -| `netcoreapp2.1` | 851 | -| `netcoreapp2.2` | 851 | -| `netcoreapp3.0` | 806 | -| `netcoreapp3.1` | 805 | -| `net5.0` | 677 | -| `net6.0` | 578 | -| `net7.0` | 423 | -| `net8.0` | 304 | -| `net9.0` | 210 | -| `net10.0` | 156 | +| `net461` | 1004 | +| `net462` | 1004 | +| `net47` | 1003 | +| `net471` | 1002 | +| `net472` | 998 | +| `net48` | 998 | +| `net481` | 998 | +| `netstandard2.0` | 1000 | +| `netstandard2.1` | 853 | +| `netcoreapp2.0` | 923 | +| `netcoreapp2.1` | 864 | +| `netcoreapp2.2` | 864 | +| `netcoreapp3.0` | 819 | +| `netcoreapp3.1` | 818 | +| `net5.0` | 690 | +| `net6.0` | 591 | +| `net7.0` | 438 | +| `net8.0` | 317 | +| `net9.0` | 223 | +| `net10.0` | 169 | | `net11.0` | 58 | -| `uap10.0` | 977 | +| `uap10.0` | 990 | @@ -96,26 +96,26 @@ This project uses features from the newest stable SDK and C# language. As such c | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 364.0KB | +356.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| netstandard2.1 | 8.5KB | 318.0KB | +309.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net461 | 8.5KB | 362.5KB | +354.0KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | -| net462 | 7.0KB | 366.0KB | +359.0KB | +9.5KB | +7.0KB | +9.5KB | +14.0KB | -| net47 | 7.0KB | 366.0KB | +359.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 365.0KB | +356.5KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | -| net472 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| net48 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| net481 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| netcoreapp2.0 | 9.0KB | 341.5KB | +332.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 321.5KB | +312.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.2 | 9.0KB | 321.5KB | +312.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.0 | 9.5KB | 315.5KB | +306.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.1 | 9.5KB | 314.0KB | +304.5KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | -| net5.0 | 9.5KB | 278.0KB | +268.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net6.0 | 10.0KB | 219.5KB | +209.5KB | +9.5KB | +6.5KB | +512bytes | +3.0KB | -| net7.0 | 10.0KB | 181.0KB | +171.0KB | +12.0KB | +8.5KB | +512bytes | +3.5KB | -| net8.0 | 9.5KB | 152.0KB | +142.5KB | +8.5KB | | +512bytes | +3.0KB | -| net9.0 | 9.5KB | 105.0KB | +95.5KB | +8.5KB | | +512bytes | +3.5KB | -| net10.0 | 10.0KB | 82.5KB | +72.5KB | +8.5KB | | +512bytes | +3.5KB | +| netstandard2.0 | 8.0KB | 365.5KB | +357.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| netstandard2.1 | 8.5KB | 319.5KB | +311.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net461 | 8.5KB | 364.5KB | +356.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net462 | 7.0KB | 368.0KB | +361.0KB | +7.5KB | +6.5KB | +9.0KB | +13.5KB | +| net47 | 7.0KB | 367.5KB | +360.5KB | +7.5KB | +6.5KB | +9.5KB | +14.0KB | +| net471 | 8.5KB | 365.5KB | +357.0KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | +| net472 | 8.5KB | 365.5KB | +357.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net48 | 8.5KB | 365.5KB | +357.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net481 | 8.5KB | 365.5KB | +357.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| netcoreapp2.0 | 9.0KB | 343.0KB | +334.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.1 | 9.0KB | 323.0KB | +314.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.2 | 9.0KB | 323.0KB | +314.0KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp3.0 | 9.5KB | 317.0KB | +307.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | +| netcoreapp3.1 | 9.5KB | 315.5KB | +306.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net5.0 | 9.5KB | 279.5KB | +270.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net6.0 | 10.0KB | 221.0KB | +211.0KB | +10.0KB | +7.0KB | +512bytes | +3.5KB | +| net7.0 | 10.0KB | 183.5KB | +173.5KB | +12.0KB | +8.5KB | +3.5KB | +6.0KB | +| net8.0 | 9.5KB | 156.5KB | +147.0KB | +8.5KB | | +512bytes | +3.5KB | +| net9.0 | 9.5KB | 109.5KB | +100.0KB | +8.5KB | | +512bytes | +3.5KB | +| net10.0 | 10.0KB | 87.5KB | +77.5KB | +8.5KB | | +512bytes | +3.0KB | | net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.5KB | +512bytes | +1.0KB | +4.0KB | @@ -123,26 +123,26 @@ This project uses features from the newest stable SDK and C# language. As such c | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 534.0KB | +526.0KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| netstandard2.1 | 8.5KB | 461.4KB | +452.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net461 | 8.5KB | 533.6KB | +525.1KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | -| net462 | 7.0KB | 537.1KB | +530.1KB | +17.2KB | +8.7KB | +14.4KB | +19.4KB | -| net47 | 7.0KB | 536.8KB | +529.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 535.5KB | +527.0KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | -| net472 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| net48 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| net481 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| netcoreapp2.0 | 9.0KB | 501.0KB | +492.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 468.6KB | +459.6KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.2 | 9.0KB | 468.6KB | +459.6KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.0 | 9.5KB | 454.5KB | +445.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.1 | 9.5KB | 453.0KB | +443.5KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | -| net5.0 | 9.5KB | 398.9KB | +389.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net6.0 | 10.0KB | 320.4KB | +310.4KB | +17.2KB | +8.2KB | +1.1KB | +3.7KB | -| net7.0 | 10.0KB | 263.1KB | +253.1KB | +19.6KB | +9.9KB | +1.1KB | +4.2KB | -| net8.0 | 9.5KB | 218.7KB | +209.2KB | +16.0KB | +299bytes | +1.1KB | +3.7KB | -| net9.0 | 9.5KB | 150.6KB | +141.1KB | +16.0KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 119.4KB | +109.4KB | +16.0KB | | +1.1KB | +4.2KB | +| netstandard2.0 | 8.0KB | 536.9KB | +528.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| netstandard2.1 | 8.5KB | 464.3KB | +455.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net461 | 8.5KB | 536.9KB | +528.4KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net462 | 7.0KB | 540.4KB | +533.4KB | +15.2KB | +8.2KB | +13.9KB | +18.9KB | +| net47 | 7.0KB | 539.7KB | +532.7KB | +15.2KB | +8.2KB | +14.4KB | +19.4KB | +| net471 | 8.5KB | 537.3KB | +528.8KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | +| net472 | 8.5KB | 536.2KB | +527.7KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net48 | 8.5KB | 536.2KB | +527.7KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net481 | 8.5KB | 536.2KB | +527.7KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| netcoreapp2.0 | 9.0KB | 503.8KB | +494.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.1 | 9.0KB | 471.5KB | +462.5KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.2 | 9.0KB | 471.5KB | +462.5KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp3.0 | 9.5KB | 457.4KB | +447.9KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | +| netcoreapp3.1 | 9.5KB | 455.9KB | +446.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net5.0 | 9.5KB | 401.8KB | +392.3KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net6.0 | 10.0KB | 323.3KB | +313.3KB | +17.7KB | +8.7KB | +1.1KB | +4.2KB | +| net7.0 | 10.0KB | 267.5KB | +257.5KB | +19.6KB | +9.9KB | +4.1KB | +6.7KB | +| net8.0 | 9.5KB | 226.7KB | +217.2KB | +16.0KB | +299bytes | +1.1KB | +4.2KB | +| net9.0 | 9.5KB | 158.5KB | +149.0KB | +16.0KB | | +1.1KB | +4.2KB | +| net10.0 | 10.0KB | 127.8KB | +117.8KB | +16.0KB | | +1.1KB | +3.7KB | | net11.0 | 10.0KB | 30.4KB | +20.4KB | +17.0KB | +512bytes | +1.6KB | +4.7KB | @@ -714,6 +714,7 @@ The class `Polyfill` includes the following extension methods: * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryformat?view=net-11.0#system-byte-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryformat?view=net-11.0#system-byte-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `byte Log10(byte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, byte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse?view=net-11.0#system-byte-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-byte@)) * `bool TryParse(ReadOnlySpan, IFormatProvider?, byte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse?view=net-11.0#system-byte-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-byte@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, byte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse?view=net-11.0#system-byte-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-byte@)) @@ -1197,10 +1198,16 @@ The class `Polyfill` includes the following extension methods: * `ReadOnlyCollection AsReadOnly()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.collectionextensions.asreadonly?view=net-11.0#system-collections-generic-collectionextensions-asreadonly-1(system-collections-generic-ilist((-0)))) +#### Int128 + + * `Int128 Log10(Int128)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int128.log10?view=net-11.0) + + #### Int16 * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryformat?view=net-11.0#system-int16-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryformat?view=net-11.0#system-int16-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `short Log10(short)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, short)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryparse?view=net-11.0#system-int16-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-int16@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, short)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryparse?view=net-11.0#system-int16-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-int16@)) * `bool TryParse(ReadOnlySpan, short)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int16.tryparse?view=net-11.0#system-int16-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-int16@)) @@ -1215,6 +1222,7 @@ The class `Polyfill` includes the following extension methods: * `float Int32BitsToSingle(int)` * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryformat?view=net-11.0#system-int32-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryformat?view=net-11.0#system-int32-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `int Log10(int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=net-11.0#system-int32-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-int32@)) * `bool TryParse(ReadOnlySpan, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=net-11.0#system-int32-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-int32@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=net-11.0#system-int32-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-int32@)) @@ -1228,6 +1236,7 @@ The class `Polyfill` includes the following extension methods: * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryformat?view=net-11.0#system-int64-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryformat?view=net-11.0#system-int64-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `long Log10(long)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, long)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse?view=net-11.0#system-int64-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-int64@)) * `bool TryParse(ReadOnlySpan, long)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse?view=net-11.0#system-int64-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-int64@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, long)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse?view=net-11.0#system-int64-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-int64@)) @@ -1243,6 +1252,7 @@ The class `Polyfill` includes the following extension methods: #### IntPtr + * `nint Log10(nint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.intptr.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, nint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.intptr.tryparse?view=net-11.0#system-intptr-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-intptr@)) * `bool TryParse(ReadOnlySpan, nint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.intptr.tryparse?view=net-11.0#system-intptr-tryparse(system-readonlyspan((system-byte))-system-intptr@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, nint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.intptr.tryparse?view=net-11.0#system-intptr-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-intptr@)) @@ -1601,6 +1611,7 @@ The class `Polyfill` includes the following extension methods: * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryformat?view=net-11.0#system-sbyte-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryformat?view=net-11.0#system-sbyte-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `sbyte Log10(sbyte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, sbyte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryparse?view=net-11.0#system-sbyte-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-sbyte@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, sbyte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryparse?view=net-11.0#system-sbyte-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-sbyte@)) * `bool TryParse(ReadOnlySpan, sbyte)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.tryparse?view=net-11.0#system-sbyte-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-sbyte@)) @@ -1936,10 +1947,16 @@ The class `Polyfill` includes the following extension methods: * `ValueTask SendAsync(ReadOnlyMemory, string?, int, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.sendasync?view=net-11.0#system-net-sockets-udpclient-sendasync(system-readonlymemory((system-byte))-system-string-system-int32-system-threading-cancellationtoken)) +#### UInt128 + + * `UInt128 Log10(UInt128)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint128.log10?view=net-11.0) + + #### UInt16 * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryformat?view=net-11.0#system-uint16-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryformat?view=net-11.0#system-uint16-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) + * `ushort Log10(ushort)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, ushort)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryparse?view=net-11.0#system-uint16-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-uint16@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, ushort)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryparse?view=net-11.0#system-uint16-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-uint16@)) * `bool TryParse(ReadOnlySpan, ushort)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint16.tryparse?view=net-11.0#system-uint16-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-uint16@)) @@ -1954,6 +1971,7 @@ The class `Polyfill` includes the following extension methods: * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryformat?view=net-11.0#system-uint32-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryformat?view=net-11.0#system-uint32-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `float UInt32BitsToSingle(uint)` + * `uint Log10(uint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, uint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryparse?view=net-11.0#system-uint32-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-uint32@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, uint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryparse?view=net-11.0#system-uint32-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-uint32@)) * `bool TryParse(ReadOnlySpan, uint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tryparse?view=net-11.0#system-uint32-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-uint32@)) @@ -1968,6 +1986,7 @@ The class `Polyfill` includes the following extension methods: * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryformat?view=net-11.0#system-uint64-tryformat(system-span((system-byte))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `bool TryFormat(Span, int, ReadOnlySpan, IFormatProvider?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryformat?view=net-11.0#system-uint64-tryformat(system-span((system-char))-system-int32@-system-readonlyspan((system-char))-system-iformatprovider)) * `double UInt64BitsToDouble(ulong)` + * `ulong Log10(ulong)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, ulong)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryparse?view=net-11.0#system-uint64-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-uint64@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, ulong)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryparse?view=net-11.0#system-uint64-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-uint64@)) * `bool TryParse(ReadOnlySpan, ulong)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryparse?view=net-11.0#system-uint64-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-uint64@)) @@ -1979,6 +1998,7 @@ The class `Polyfill` includes the following extension methods: #### UIntPtr + * `nuint Log10(nuint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uintptr.log10?view=net-11.0) * `bool TryParse(ReadOnlySpan, IFormatProvider?, nuint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uintptr.tryparse?view=net-11.0#system-uintptr-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-uintptr@)) * `bool TryParse(ReadOnlySpan, nuint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uintptr.tryparse?view=net-11.0#system-uintptr-tryparse(system-readonlyspan((system-byte))-system-uintptr@)) * `bool TryParse(ReadOnlySpan, NumberStyles, IFormatProvider?, nuint)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uintptr.tryparse?view=net-11.0#system-uintptr-tryparse(system-readonlyspan((system-byte))-system-globalization-numberstyles-system-iformatprovider-system-uintptr@)) @@ -2395,7 +2415,7 @@ void ObjectDisposedExceptionExample(bool isDisposed) ObjectDisposedException.ThrowIf(isDisposed, typeof(Consume)); } ``` -snippet source | anchor +snippet source | anchor @@ -2414,7 +2434,7 @@ void EnsureExample(Order order, Customer customer, string customerId, string ema this.quantity = Ensure.NotNegativeOrZero(quantity); } ``` -snippet source | anchor +snippet source | anchor diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index 3c14b5e4..6d69a3da 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -593,6 +593,24 @@ void BinaryPrimitives_Methods() } #endif + void Log10_Methods() + { + byte byteLog10 = byte.Log10(100); + sbyte sbyteLog10 = sbyte.Log10(100); + short shortLog10 = short.Log10(100); + ushort ushortLog10 = ushort.Log10(100); + int intLog10 = int.Log10(100); + uint uintLog10 = uint.Log10(100); + long longLog10 = long.Log10(100); + ulong ulongLog10 = ulong.Log10(100); + nint nintLog10 = nint.Log10(100); + nuint nuintLog10 = nuint.Log10(100); +#if NET7_0_OR_GREATER + Int128 int128Log10 = Int128.Log10(100); + UInt128 uint128Log10 = UInt128.Log10(100); +#endif + } + void Byte_Methods() { byte.TryParse(s: "1", provider: null, result: out _); diff --git a/src/Polyfill/Numbers/BytePolyfill.cs b/src/Polyfill/Numbers/BytePolyfill.cs index 38418da2..beaac898 100644 --- a/src/Polyfill/Numbers/BytePolyfill.cs +++ b/src/Polyfill/Numbers/BytePolyfill.cs @@ -1,6 +1,6 @@ #nullable enable -#if !NET8_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; @@ -13,6 +13,7 @@ static partial class Polyfill { extension(Byte) { +#if !NET8_0_OR_GREATER #if !NET7_0_OR_GREATER /// @@ -80,6 +81,14 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro #endif #endif +#endif + + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.byte.log10?view=net-11.0 + public static byte Log10(byte value) => + (byte) Log10Core(value); } } #endif diff --git a/src/Polyfill/Numbers/Int128Polyfill.cs b/src/Polyfill/Numbers/Int128Polyfill.cs new file mode 100644 index 00000000..71368ca2 --- /dev/null +++ b/src/Polyfill/Numbers/Int128Polyfill.cs @@ -0,0 +1,39 @@ +#if NET7_0_OR_GREATER && !NET11_0_OR_GREATER + +namespace Polyfills; + +using System; + +static partial class Polyfill +{ + extension(Int128) + { + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int128.log10?view=net-11.0 + public static Int128 Log10(Int128 value) + { + if (value < Int128.Zero) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + + return Log10Core((UInt128) value); + } + } + + static Int128 Log10Core(UInt128 value) + { + var result = Int128.Zero; + while (value >= 10) + { + value /= 10; + result++; + } + + return result; + } +} + +#endif diff --git a/src/Polyfill/Numbers/Int16Polyfill.cs b/src/Polyfill/Numbers/Int16Polyfill.cs index d8b641c7..3bf9422d 100644 --- a/src/Polyfill/Numbers/Int16Polyfill.cs +++ b/src/Polyfill/Numbers/Int16Polyfill.cs @@ -1,4 +1,4 @@ -#if !NET8_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; @@ -11,6 +11,7 @@ static partial class Polyfill { extension(short) { +#if !NET8_0_OR_GREATER #if !NET7_0_OR_GREATER /// @@ -77,6 +78,21 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out #endif #endif +#endif + + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int16.log10?view=net-11.0 + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + + return (short) Log10Core((ulong) value); + } } } #endif diff --git a/src/Polyfill/Numbers/Int32Polyfill.cs b/src/Polyfill/Numbers/Int32Polyfill.cs index b35e2c54..cce948ae 100644 --- a/src/Polyfill/Numbers/Int32Polyfill.cs +++ b/src/Polyfill/Numbers/Int32Polyfill.cs @@ -1,4 +1,4 @@ -#if !NET8_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; @@ -11,6 +11,7 @@ static partial class Polyfill { extension(int) { +#if !NET8_0_OR_GREATER #if !NET7_0_OR_GREATER /// @@ -79,6 +80,33 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out #endif #endif +#endif + + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int32.log10?view=net-11.0 + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + + return (int) Log10Core((ulong) value); + } + } + + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + + return result; } } #endif diff --git a/src/Polyfill/Numbers/Int64Polyfill.cs b/src/Polyfill/Numbers/Int64Polyfill.cs index 2402d0e2..5a51b485 100644 --- a/src/Polyfill/Numbers/Int64Polyfill.cs +++ b/src/Polyfill/Numbers/Int64Polyfill.cs @@ -1,4 +1,4 @@ -#if !NET8_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; @@ -11,6 +11,7 @@ static partial class Polyfill { extension(long) { +#if !NET8_0_OR_GREATER #if !NET7_0_OR_GREATER /// @@ -79,6 +80,21 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out #endif #endif +#endif + + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.int64.log10?view=net-11.0 + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + + return (long) Log10Core((ulong) value); + } } } #endif diff --git a/src/Polyfill/Numbers/IntPtrPolyfill.cs b/src/Polyfill/Numbers/IntPtrPolyfill.cs index 96c6ba90..e93262ef 100644 --- a/src/Polyfill/Numbers/IntPtrPolyfill.cs +++ b/src/Polyfill/Numbers/IntPtrPolyfill.cs @@ -1,4 +1,4 @@ -#if !NET8_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; @@ -11,6 +11,7 @@ static partial class Polyfill { extension(nint) { +#if !NET8_0_OR_GREATER #if !NET5_0_OR_GREATER /// @@ -115,6 +116,21 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out #endif #endif +#endif + + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.intptr.log10?view=net-11.0 + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + + return (nint) Log10Core((ulong) value); + } } } #endif diff --git a/src/Polyfill/Numbers/SBytePolyfill.cs b/src/Polyfill/Numbers/SBytePolyfill.cs index 9ba77256..f4257c78 100644 --- a/src/Polyfill/Numbers/SBytePolyfill.cs +++ b/src/Polyfill/Numbers/SBytePolyfill.cs @@ -1,4 +1,4 @@ -#if !NET8_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; @@ -11,6 +11,7 @@ static partial class Polyfill { extension(sbyte) { +#if !NET8_0_OR_GREATER #if !NET7_0_OR_GREATER /// @@ -79,6 +80,21 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out #endif #endif +#endif + + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.log10?view=net-11.0 + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + + return (sbyte) Log10Core((ulong) value); + } } } #endif diff --git a/src/Polyfill/Numbers/UInt128Polyfill.cs b/src/Polyfill/Numbers/UInt128Polyfill.cs new file mode 100644 index 00000000..ef8bb84b --- /dev/null +++ b/src/Polyfill/Numbers/UInt128Polyfill.cs @@ -0,0 +1,20 @@ +#if NET7_0_OR_GREATER && !NET11_0_OR_GREATER + +namespace Polyfills; + +using System; + +static partial class Polyfill +{ + extension(UInt128) + { + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.uint128.log10?view=net-11.0 + public static UInt128 Log10(UInt128 value) => + (UInt128) Log10Core(value); + } +} + +#endif diff --git a/src/Polyfill/Numbers/UInt16Polyfill.cs b/src/Polyfill/Numbers/UInt16Polyfill.cs index e792053b..a0299101 100644 --- a/src/Polyfill/Numbers/UInt16Polyfill.cs +++ b/src/Polyfill/Numbers/UInt16Polyfill.cs @@ -1,4 +1,4 @@ -#if !NET8_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; @@ -11,6 +11,7 @@ static partial class Polyfill { extension(ushort) { +#if !NET8_0_OR_GREATER #if !NET7_0_OR_GREATER /// @@ -78,6 +79,14 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out #endif #endif +#endif + + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.uint16.log10?view=net-11.0 + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Polyfill/Numbers/UInt32Polyfill.cs b/src/Polyfill/Numbers/UInt32Polyfill.cs index 4fcc745c..72af6885 100644 --- a/src/Polyfill/Numbers/UInt32Polyfill.cs +++ b/src/Polyfill/Numbers/UInt32Polyfill.cs @@ -1,4 +1,4 @@ -#if !NET8_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; @@ -11,6 +11,7 @@ static partial class Polyfill { extension(uint) { +#if !NET8_0_OR_GREATER #if !NET7_0_OR_GREATER /// @@ -79,6 +80,14 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out #endif #endif +#endif + + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.uint32.log10?view=net-11.0 + public static uint Log10(uint value) => + (uint) Log10Core(value); } } #endif diff --git a/src/Polyfill/Numbers/UInt64Polyfill.cs b/src/Polyfill/Numbers/UInt64Polyfill.cs index ced8b84f..8cb61b59 100644 --- a/src/Polyfill/Numbers/UInt64Polyfill.cs +++ b/src/Polyfill/Numbers/UInt64Polyfill.cs @@ -1,4 +1,4 @@ -#if !NET8_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; @@ -11,6 +11,7 @@ static partial class Polyfill { extension(ulong) { +#if !NET8_0_OR_GREATER #if !NET7_0_OR_GREATER /// @@ -79,6 +80,14 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out #endif #endif +#endif + + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.uint64.log10?view=net-11.0 + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Polyfill/Numbers/UIntPtrPolyfill.cs b/src/Polyfill/Numbers/UIntPtrPolyfill.cs index 7186e2e6..26849c60 100644 --- a/src/Polyfill/Numbers/UIntPtrPolyfill.cs +++ b/src/Polyfill/Numbers/UIntPtrPolyfill.cs @@ -1,4 +1,4 @@ -#if !NET8_0_OR_GREATER +#if !NET11_0_OR_GREATER namespace Polyfills; @@ -11,6 +11,7 @@ static partial class Polyfill { extension(nuint) { +#if !NET8_0_OR_GREATER #if !NET5_0_OR_GREATER /// @@ -115,6 +116,14 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out #endif #endif +#endif + + /// + /// Computes the base-10 logarithm of a value. + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.uintptr.log10?view=net-11.0 + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } #endif diff --git a/src/Split/net10.0/Numbers/BytePolyfill.cs b/src/Split/net10.0/Numbers/BytePolyfill.cs new file mode 100644 index 00000000..f81a30e6 --- /dev/null +++ b/src/Split/net10.0/Numbers/BytePolyfill.cs @@ -0,0 +1,18 @@ +// +#pragma warning disable +#nullable enable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(Byte) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); + } +} diff --git a/src/Split/net10.0/Numbers/Int128Polyfill.cs b/src/Split/net10.0/Numbers/Int128Polyfill.cs new file mode 100644 index 00000000..b18f70a1 --- /dev/null +++ b/src/Split/net10.0/Numbers/Int128Polyfill.cs @@ -0,0 +1,31 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + extension(Int128) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static Int128 Log10(Int128 value) + { + if (value < Int128.Zero) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return Log10Core((UInt128) value); + } + } + static Int128 Log10Core(UInt128 value) + { + var result = Int128.Zero; + while (value >= 10) + { + value /= 10; + result++; + } + return result; + } +} diff --git a/src/Split/net10.0/Numbers/Int16Polyfill.cs b/src/Split/net10.0/Numbers/Int16Polyfill.cs new file mode 100644 index 00000000..ecedff30 --- /dev/null +++ b/src/Split/net10.0/Numbers/Int16Polyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(short) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net10.0/Numbers/Int32Polyfill.cs b/src/Split/net10.0/Numbers/Int32Polyfill.cs new file mode 100644 index 00000000..7409a64d --- /dev/null +++ b/src/Split/net10.0/Numbers/Int32Polyfill.cs @@ -0,0 +1,33 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(int) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; + } +} diff --git a/src/Split/net10.0/Numbers/Int64Polyfill.cs b/src/Split/net10.0/Numbers/Int64Polyfill.cs new file mode 100644 index 00000000..e602de75 --- /dev/null +++ b/src/Split/net10.0/Numbers/Int64Polyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(long) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net10.0/Numbers/IntPtrPolyfill.cs b/src/Split/net10.0/Numbers/IntPtrPolyfill.cs new file mode 100644 index 00000000..57fe93fc --- /dev/null +++ b/src/Split/net10.0/Numbers/IntPtrPolyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(nint) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net10.0/Numbers/SBytePolyfill.cs b/src/Split/net10.0/Numbers/SBytePolyfill.cs new file mode 100644 index 00000000..46cba2c7 --- /dev/null +++ b/src/Split/net10.0/Numbers/SBytePolyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(sbyte) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net10.0/Numbers/UInt128Polyfill.cs b/src/Split/net10.0/Numbers/UInt128Polyfill.cs new file mode 100644 index 00000000..c3c33950 --- /dev/null +++ b/src/Split/net10.0/Numbers/UInt128Polyfill.cs @@ -0,0 +1,15 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + extension(UInt128) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static UInt128 Log10(UInt128 value) => + (UInt128) Log10Core(value); + } +} diff --git a/src/Split/net10.0/Numbers/UInt16Polyfill.cs b/src/Split/net10.0/Numbers/UInt16Polyfill.cs new file mode 100644 index 00000000..23ef736f --- /dev/null +++ b/src/Split/net10.0/Numbers/UInt16Polyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(ushort) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); + } +} diff --git a/src/Split/net10.0/Numbers/UInt32Polyfill.cs b/src/Split/net10.0/Numbers/UInt32Polyfill.cs new file mode 100644 index 00000000..29aab694 --- /dev/null +++ b/src/Split/net10.0/Numbers/UInt32Polyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(uint) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); + } +} diff --git a/src/Split/net10.0/Numbers/UInt64Polyfill.cs b/src/Split/net10.0/Numbers/UInt64Polyfill.cs new file mode 100644 index 00000000..4ac98b2c --- /dev/null +++ b/src/Split/net10.0/Numbers/UInt64Polyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(ulong) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); + } +} diff --git a/src/Split/net10.0/Numbers/UIntPtrPolyfill.cs b/src/Split/net10.0/Numbers/UIntPtrPolyfill.cs new file mode 100644 index 00000000..8eb6c210 --- /dev/null +++ b/src/Split/net10.0/Numbers/UIntPtrPolyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(nuint) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); + } +} diff --git a/src/Split/net461/Numbers/BytePolyfill.cs b/src/Split/net461/Numbers/BytePolyfill.cs index ef3f744e..aec10ff3 100644 --- a/src/Split/net461/Numbers/BytePolyfill.cs +++ b/src/Split/net461/Numbers/BytePolyfill.cs @@ -46,5 +46,10 @@ public static bool TryParse(ReadOnlySpan s, out byte result) => public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/net461/Numbers/Int16Polyfill.cs b/src/Split/net461/Numbers/Int16Polyfill.cs index 5eb1b384..cd72ce5b 100644 --- a/src/Split/net461/Numbers/Int16Polyfill.cs +++ b/src/Split/net461/Numbers/Int16Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/net461/Numbers/Int32Polyfill.cs b/src/Split/net461/Numbers/Int32Polyfill.cs index 549ff189..6b87843d 100644 --- a/src/Split/net461/Numbers/Int32Polyfill.cs +++ b/src/Split/net461/Numbers/Int32Polyfill.cs @@ -45,5 +45,26 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/net461/Numbers/Int64Polyfill.cs b/src/Split/net461/Numbers/Int64Polyfill.cs index bd33ce0e..682711be 100644 --- a/src/Split/net461/Numbers/Int64Polyfill.cs +++ b/src/Split/net461/Numbers/Int64Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/net461/Numbers/IntPtrPolyfill.cs b/src/Split/net461/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/net461/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net461/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/net461/Numbers/SBytePolyfill.cs b/src/Split/net461/Numbers/SBytePolyfill.cs index 97411565..b2c56485 100644 --- a/src/Split/net461/Numbers/SBytePolyfill.cs +++ b/src/Split/net461/Numbers/SBytePolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/net461/Numbers/UInt16Polyfill.cs b/src/Split/net461/Numbers/UInt16Polyfill.cs index 34f39f97..1284c8d1 100644 --- a/src/Split/net461/Numbers/UInt16Polyfill.cs +++ b/src/Split/net461/Numbers/UInt16Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/net461/Numbers/UInt32Polyfill.cs b/src/Split/net461/Numbers/UInt32Polyfill.cs index 859149be..91159c5e 100644 --- a/src/Split/net461/Numbers/UInt32Polyfill.cs +++ b/src/Split/net461/Numbers/UInt32Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/net461/Numbers/UInt64Polyfill.cs b/src/Split/net461/Numbers/UInt64Polyfill.cs index c14bb347..d8fa1789 100644 --- a/src/Split/net461/Numbers/UInt64Polyfill.cs +++ b/src/Split/net461/Numbers/UInt64Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/net461/Numbers/UIntPtrPolyfill.cs b/src/Split/net461/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/net461/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net461/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/net462/Numbers/BytePolyfill.cs b/src/Split/net462/Numbers/BytePolyfill.cs index ef3f744e..aec10ff3 100644 --- a/src/Split/net462/Numbers/BytePolyfill.cs +++ b/src/Split/net462/Numbers/BytePolyfill.cs @@ -46,5 +46,10 @@ public static bool TryParse(ReadOnlySpan s, out byte result) => public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/net462/Numbers/Int16Polyfill.cs b/src/Split/net462/Numbers/Int16Polyfill.cs index 5eb1b384..cd72ce5b 100644 --- a/src/Split/net462/Numbers/Int16Polyfill.cs +++ b/src/Split/net462/Numbers/Int16Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/net462/Numbers/Int32Polyfill.cs b/src/Split/net462/Numbers/Int32Polyfill.cs index 549ff189..6b87843d 100644 --- a/src/Split/net462/Numbers/Int32Polyfill.cs +++ b/src/Split/net462/Numbers/Int32Polyfill.cs @@ -45,5 +45,26 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/net462/Numbers/Int64Polyfill.cs b/src/Split/net462/Numbers/Int64Polyfill.cs index bd33ce0e..682711be 100644 --- a/src/Split/net462/Numbers/Int64Polyfill.cs +++ b/src/Split/net462/Numbers/Int64Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/net462/Numbers/IntPtrPolyfill.cs b/src/Split/net462/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/net462/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net462/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/net462/Numbers/SBytePolyfill.cs b/src/Split/net462/Numbers/SBytePolyfill.cs index 97411565..b2c56485 100644 --- a/src/Split/net462/Numbers/SBytePolyfill.cs +++ b/src/Split/net462/Numbers/SBytePolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/net462/Numbers/UInt16Polyfill.cs b/src/Split/net462/Numbers/UInt16Polyfill.cs index 34f39f97..1284c8d1 100644 --- a/src/Split/net462/Numbers/UInt16Polyfill.cs +++ b/src/Split/net462/Numbers/UInt16Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/net462/Numbers/UInt32Polyfill.cs b/src/Split/net462/Numbers/UInt32Polyfill.cs index 859149be..91159c5e 100644 --- a/src/Split/net462/Numbers/UInt32Polyfill.cs +++ b/src/Split/net462/Numbers/UInt32Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/net462/Numbers/UInt64Polyfill.cs b/src/Split/net462/Numbers/UInt64Polyfill.cs index c14bb347..d8fa1789 100644 --- a/src/Split/net462/Numbers/UInt64Polyfill.cs +++ b/src/Split/net462/Numbers/UInt64Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/net462/Numbers/UIntPtrPolyfill.cs b/src/Split/net462/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/net462/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net462/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/net47/Numbers/BytePolyfill.cs b/src/Split/net47/Numbers/BytePolyfill.cs index ef3f744e..aec10ff3 100644 --- a/src/Split/net47/Numbers/BytePolyfill.cs +++ b/src/Split/net47/Numbers/BytePolyfill.cs @@ -46,5 +46,10 @@ public static bool TryParse(ReadOnlySpan s, out byte result) => public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/net47/Numbers/Int16Polyfill.cs b/src/Split/net47/Numbers/Int16Polyfill.cs index 5eb1b384..cd72ce5b 100644 --- a/src/Split/net47/Numbers/Int16Polyfill.cs +++ b/src/Split/net47/Numbers/Int16Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/net47/Numbers/Int32Polyfill.cs b/src/Split/net47/Numbers/Int32Polyfill.cs index 549ff189..6b87843d 100644 --- a/src/Split/net47/Numbers/Int32Polyfill.cs +++ b/src/Split/net47/Numbers/Int32Polyfill.cs @@ -45,5 +45,26 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/net47/Numbers/Int64Polyfill.cs b/src/Split/net47/Numbers/Int64Polyfill.cs index bd33ce0e..682711be 100644 --- a/src/Split/net47/Numbers/Int64Polyfill.cs +++ b/src/Split/net47/Numbers/Int64Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/net47/Numbers/IntPtrPolyfill.cs b/src/Split/net47/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/net47/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net47/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/net47/Numbers/SBytePolyfill.cs b/src/Split/net47/Numbers/SBytePolyfill.cs index 97411565..b2c56485 100644 --- a/src/Split/net47/Numbers/SBytePolyfill.cs +++ b/src/Split/net47/Numbers/SBytePolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/net47/Numbers/UInt16Polyfill.cs b/src/Split/net47/Numbers/UInt16Polyfill.cs index 34f39f97..1284c8d1 100644 --- a/src/Split/net47/Numbers/UInt16Polyfill.cs +++ b/src/Split/net47/Numbers/UInt16Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/net47/Numbers/UInt32Polyfill.cs b/src/Split/net47/Numbers/UInt32Polyfill.cs index 859149be..91159c5e 100644 --- a/src/Split/net47/Numbers/UInt32Polyfill.cs +++ b/src/Split/net47/Numbers/UInt32Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/net47/Numbers/UInt64Polyfill.cs b/src/Split/net47/Numbers/UInt64Polyfill.cs index c14bb347..d8fa1789 100644 --- a/src/Split/net47/Numbers/UInt64Polyfill.cs +++ b/src/Split/net47/Numbers/UInt64Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/net47/Numbers/UIntPtrPolyfill.cs b/src/Split/net47/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/net47/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net47/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/net471/Numbers/BytePolyfill.cs b/src/Split/net471/Numbers/BytePolyfill.cs index ef3f744e..aec10ff3 100644 --- a/src/Split/net471/Numbers/BytePolyfill.cs +++ b/src/Split/net471/Numbers/BytePolyfill.cs @@ -46,5 +46,10 @@ public static bool TryParse(ReadOnlySpan s, out byte result) => public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/net471/Numbers/Int16Polyfill.cs b/src/Split/net471/Numbers/Int16Polyfill.cs index 5eb1b384..cd72ce5b 100644 --- a/src/Split/net471/Numbers/Int16Polyfill.cs +++ b/src/Split/net471/Numbers/Int16Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/net471/Numbers/Int32Polyfill.cs b/src/Split/net471/Numbers/Int32Polyfill.cs index 549ff189..6b87843d 100644 --- a/src/Split/net471/Numbers/Int32Polyfill.cs +++ b/src/Split/net471/Numbers/Int32Polyfill.cs @@ -45,5 +45,26 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/net471/Numbers/Int64Polyfill.cs b/src/Split/net471/Numbers/Int64Polyfill.cs index bd33ce0e..682711be 100644 --- a/src/Split/net471/Numbers/Int64Polyfill.cs +++ b/src/Split/net471/Numbers/Int64Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/net471/Numbers/IntPtrPolyfill.cs b/src/Split/net471/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/net471/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net471/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/net471/Numbers/SBytePolyfill.cs b/src/Split/net471/Numbers/SBytePolyfill.cs index 97411565..b2c56485 100644 --- a/src/Split/net471/Numbers/SBytePolyfill.cs +++ b/src/Split/net471/Numbers/SBytePolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/net471/Numbers/UInt16Polyfill.cs b/src/Split/net471/Numbers/UInt16Polyfill.cs index 34f39f97..1284c8d1 100644 --- a/src/Split/net471/Numbers/UInt16Polyfill.cs +++ b/src/Split/net471/Numbers/UInt16Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/net471/Numbers/UInt32Polyfill.cs b/src/Split/net471/Numbers/UInt32Polyfill.cs index 859149be..91159c5e 100644 --- a/src/Split/net471/Numbers/UInt32Polyfill.cs +++ b/src/Split/net471/Numbers/UInt32Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/net471/Numbers/UInt64Polyfill.cs b/src/Split/net471/Numbers/UInt64Polyfill.cs index c14bb347..d8fa1789 100644 --- a/src/Split/net471/Numbers/UInt64Polyfill.cs +++ b/src/Split/net471/Numbers/UInt64Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/net471/Numbers/UIntPtrPolyfill.cs b/src/Split/net471/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/net471/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net471/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/net472/Numbers/BytePolyfill.cs b/src/Split/net472/Numbers/BytePolyfill.cs index ef3f744e..aec10ff3 100644 --- a/src/Split/net472/Numbers/BytePolyfill.cs +++ b/src/Split/net472/Numbers/BytePolyfill.cs @@ -46,5 +46,10 @@ public static bool TryParse(ReadOnlySpan s, out byte result) => public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/net472/Numbers/Int16Polyfill.cs b/src/Split/net472/Numbers/Int16Polyfill.cs index 5eb1b384..cd72ce5b 100644 --- a/src/Split/net472/Numbers/Int16Polyfill.cs +++ b/src/Split/net472/Numbers/Int16Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/net472/Numbers/Int32Polyfill.cs b/src/Split/net472/Numbers/Int32Polyfill.cs index 549ff189..6b87843d 100644 --- a/src/Split/net472/Numbers/Int32Polyfill.cs +++ b/src/Split/net472/Numbers/Int32Polyfill.cs @@ -45,5 +45,26 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/net472/Numbers/Int64Polyfill.cs b/src/Split/net472/Numbers/Int64Polyfill.cs index bd33ce0e..682711be 100644 --- a/src/Split/net472/Numbers/Int64Polyfill.cs +++ b/src/Split/net472/Numbers/Int64Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/net472/Numbers/IntPtrPolyfill.cs b/src/Split/net472/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/net472/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net472/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/net472/Numbers/SBytePolyfill.cs b/src/Split/net472/Numbers/SBytePolyfill.cs index 97411565..b2c56485 100644 --- a/src/Split/net472/Numbers/SBytePolyfill.cs +++ b/src/Split/net472/Numbers/SBytePolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/net472/Numbers/UInt16Polyfill.cs b/src/Split/net472/Numbers/UInt16Polyfill.cs index 34f39f97..1284c8d1 100644 --- a/src/Split/net472/Numbers/UInt16Polyfill.cs +++ b/src/Split/net472/Numbers/UInt16Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/net472/Numbers/UInt32Polyfill.cs b/src/Split/net472/Numbers/UInt32Polyfill.cs index 859149be..91159c5e 100644 --- a/src/Split/net472/Numbers/UInt32Polyfill.cs +++ b/src/Split/net472/Numbers/UInt32Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/net472/Numbers/UInt64Polyfill.cs b/src/Split/net472/Numbers/UInt64Polyfill.cs index c14bb347..d8fa1789 100644 --- a/src/Split/net472/Numbers/UInt64Polyfill.cs +++ b/src/Split/net472/Numbers/UInt64Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/net472/Numbers/UIntPtrPolyfill.cs b/src/Split/net472/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/net472/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net472/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/net48/Numbers/BytePolyfill.cs b/src/Split/net48/Numbers/BytePolyfill.cs index ef3f744e..aec10ff3 100644 --- a/src/Split/net48/Numbers/BytePolyfill.cs +++ b/src/Split/net48/Numbers/BytePolyfill.cs @@ -46,5 +46,10 @@ public static bool TryParse(ReadOnlySpan s, out byte result) => public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/net48/Numbers/Int16Polyfill.cs b/src/Split/net48/Numbers/Int16Polyfill.cs index 5eb1b384..cd72ce5b 100644 --- a/src/Split/net48/Numbers/Int16Polyfill.cs +++ b/src/Split/net48/Numbers/Int16Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/net48/Numbers/Int32Polyfill.cs b/src/Split/net48/Numbers/Int32Polyfill.cs index 549ff189..6b87843d 100644 --- a/src/Split/net48/Numbers/Int32Polyfill.cs +++ b/src/Split/net48/Numbers/Int32Polyfill.cs @@ -45,5 +45,26 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/net48/Numbers/Int64Polyfill.cs b/src/Split/net48/Numbers/Int64Polyfill.cs index bd33ce0e..682711be 100644 --- a/src/Split/net48/Numbers/Int64Polyfill.cs +++ b/src/Split/net48/Numbers/Int64Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/net48/Numbers/IntPtrPolyfill.cs b/src/Split/net48/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/net48/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net48/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/net48/Numbers/SBytePolyfill.cs b/src/Split/net48/Numbers/SBytePolyfill.cs index 97411565..b2c56485 100644 --- a/src/Split/net48/Numbers/SBytePolyfill.cs +++ b/src/Split/net48/Numbers/SBytePolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/net48/Numbers/UInt16Polyfill.cs b/src/Split/net48/Numbers/UInt16Polyfill.cs index 34f39f97..1284c8d1 100644 --- a/src/Split/net48/Numbers/UInt16Polyfill.cs +++ b/src/Split/net48/Numbers/UInt16Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/net48/Numbers/UInt32Polyfill.cs b/src/Split/net48/Numbers/UInt32Polyfill.cs index 859149be..91159c5e 100644 --- a/src/Split/net48/Numbers/UInt32Polyfill.cs +++ b/src/Split/net48/Numbers/UInt32Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/net48/Numbers/UInt64Polyfill.cs b/src/Split/net48/Numbers/UInt64Polyfill.cs index c14bb347..d8fa1789 100644 --- a/src/Split/net48/Numbers/UInt64Polyfill.cs +++ b/src/Split/net48/Numbers/UInt64Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/net48/Numbers/UIntPtrPolyfill.cs b/src/Split/net48/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/net48/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net48/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/net481/Numbers/BytePolyfill.cs b/src/Split/net481/Numbers/BytePolyfill.cs index ef3f744e..aec10ff3 100644 --- a/src/Split/net481/Numbers/BytePolyfill.cs +++ b/src/Split/net481/Numbers/BytePolyfill.cs @@ -46,5 +46,10 @@ public static bool TryParse(ReadOnlySpan s, out byte result) => public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/net481/Numbers/Int16Polyfill.cs b/src/Split/net481/Numbers/Int16Polyfill.cs index 5eb1b384..cd72ce5b 100644 --- a/src/Split/net481/Numbers/Int16Polyfill.cs +++ b/src/Split/net481/Numbers/Int16Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/net481/Numbers/Int32Polyfill.cs b/src/Split/net481/Numbers/Int32Polyfill.cs index 549ff189..6b87843d 100644 --- a/src/Split/net481/Numbers/Int32Polyfill.cs +++ b/src/Split/net481/Numbers/Int32Polyfill.cs @@ -45,5 +45,26 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/net481/Numbers/Int64Polyfill.cs b/src/Split/net481/Numbers/Int64Polyfill.cs index bd33ce0e..682711be 100644 --- a/src/Split/net481/Numbers/Int64Polyfill.cs +++ b/src/Split/net481/Numbers/Int64Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/net481/Numbers/IntPtrPolyfill.cs b/src/Split/net481/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/net481/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net481/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/net481/Numbers/SBytePolyfill.cs b/src/Split/net481/Numbers/SBytePolyfill.cs index 97411565..b2c56485 100644 --- a/src/Split/net481/Numbers/SBytePolyfill.cs +++ b/src/Split/net481/Numbers/SBytePolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/net481/Numbers/UInt16Polyfill.cs b/src/Split/net481/Numbers/UInt16Polyfill.cs index 34f39f97..1284c8d1 100644 --- a/src/Split/net481/Numbers/UInt16Polyfill.cs +++ b/src/Split/net481/Numbers/UInt16Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/net481/Numbers/UInt32Polyfill.cs b/src/Split/net481/Numbers/UInt32Polyfill.cs index 859149be..91159c5e 100644 --- a/src/Split/net481/Numbers/UInt32Polyfill.cs +++ b/src/Split/net481/Numbers/UInt32Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/net481/Numbers/UInt64Polyfill.cs b/src/Split/net481/Numbers/UInt64Polyfill.cs index c14bb347..d8fa1789 100644 --- a/src/Split/net481/Numbers/UInt64Polyfill.cs +++ b/src/Split/net481/Numbers/UInt64Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/net481/Numbers/UIntPtrPolyfill.cs b/src/Split/net481/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/net481/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net481/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/net5.0/Numbers/BytePolyfill.cs b/src/Split/net5.0/Numbers/BytePolyfill.cs index b3235149..30ad6afe 100644 --- a/src/Split/net5.0/Numbers/BytePolyfill.cs +++ b/src/Split/net5.0/Numbers/BytePolyfill.cs @@ -36,5 +36,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/net5.0/Numbers/Int16Polyfill.cs b/src/Split/net5.0/Numbers/Int16Polyfill.cs index 7a1f0b7c..f4310059 100644 --- a/src/Split/net5.0/Numbers/Int16Polyfill.cs +++ b/src/Split/net5.0/Numbers/Int16Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out short result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/net5.0/Numbers/Int32Polyfill.cs b/src/Split/net5.0/Numbers/Int32Polyfill.cs index 853dfb51..e455cd66 100644 --- a/src/Split/net5.0/Numbers/Int32Polyfill.cs +++ b/src/Split/net5.0/Numbers/Int32Polyfill.cs @@ -35,5 +35,26 @@ public static bool TryParse(ReadOnlySpan utf8Text, out int result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/net5.0/Numbers/Int64Polyfill.cs b/src/Split/net5.0/Numbers/Int64Polyfill.cs index e97be477..15534695 100644 --- a/src/Split/net5.0/Numbers/Int64Polyfill.cs +++ b/src/Split/net5.0/Numbers/Int64Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out long result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/net5.0/Numbers/IntPtrPolyfill.cs b/src/Split/net5.0/Numbers/IntPtrPolyfill.cs index a1d09dc1..04d77ea3 100644 --- a/src/Split/net5.0/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net5.0/Numbers/IntPtrPolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/net5.0/Numbers/SBytePolyfill.cs b/src/Split/net5.0/Numbers/SBytePolyfill.cs index 9085c3ae..d4002463 100644 --- a/src/Split/net5.0/Numbers/SBytePolyfill.cs +++ b/src/Split/net5.0/Numbers/SBytePolyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/net5.0/Numbers/UInt16Polyfill.cs b/src/Split/net5.0/Numbers/UInt16Polyfill.cs index 11d4c4ed..b067caa8 100644 --- a/src/Split/net5.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/net5.0/Numbers/UInt16Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/net5.0/Numbers/UInt32Polyfill.cs b/src/Split/net5.0/Numbers/UInt32Polyfill.cs index abdf707d..9592af7a 100644 --- a/src/Split/net5.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/net5.0/Numbers/UInt32Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/net5.0/Numbers/UInt64Polyfill.cs b/src/Split/net5.0/Numbers/UInt64Polyfill.cs index 1a1bc228..536ba2d9 100644 --- a/src/Split/net5.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/net5.0/Numbers/UInt64Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/net5.0/Numbers/UIntPtrPolyfill.cs b/src/Split/net5.0/Numbers/UIntPtrPolyfill.cs index 2d1485c1..3198624c 100644 --- a/src/Split/net5.0/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net5.0/Numbers/UIntPtrPolyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/net6.0/Numbers/BytePolyfill.cs b/src/Split/net6.0/Numbers/BytePolyfill.cs index b3235149..30ad6afe 100644 --- a/src/Split/net6.0/Numbers/BytePolyfill.cs +++ b/src/Split/net6.0/Numbers/BytePolyfill.cs @@ -36,5 +36,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/net6.0/Numbers/Int16Polyfill.cs b/src/Split/net6.0/Numbers/Int16Polyfill.cs index 7a1f0b7c..f4310059 100644 --- a/src/Split/net6.0/Numbers/Int16Polyfill.cs +++ b/src/Split/net6.0/Numbers/Int16Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out short result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/net6.0/Numbers/Int32Polyfill.cs b/src/Split/net6.0/Numbers/Int32Polyfill.cs index 853dfb51..e455cd66 100644 --- a/src/Split/net6.0/Numbers/Int32Polyfill.cs +++ b/src/Split/net6.0/Numbers/Int32Polyfill.cs @@ -35,5 +35,26 @@ public static bool TryParse(ReadOnlySpan utf8Text, out int result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/net6.0/Numbers/Int64Polyfill.cs b/src/Split/net6.0/Numbers/Int64Polyfill.cs index e97be477..15534695 100644 --- a/src/Split/net6.0/Numbers/Int64Polyfill.cs +++ b/src/Split/net6.0/Numbers/Int64Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out long result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/net6.0/Numbers/IntPtrPolyfill.cs b/src/Split/net6.0/Numbers/IntPtrPolyfill.cs index a1d09dc1..04d77ea3 100644 --- a/src/Split/net6.0/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net6.0/Numbers/IntPtrPolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/net6.0/Numbers/SBytePolyfill.cs b/src/Split/net6.0/Numbers/SBytePolyfill.cs index 9085c3ae..d4002463 100644 --- a/src/Split/net6.0/Numbers/SBytePolyfill.cs +++ b/src/Split/net6.0/Numbers/SBytePolyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/net6.0/Numbers/UInt16Polyfill.cs b/src/Split/net6.0/Numbers/UInt16Polyfill.cs index 11d4c4ed..b067caa8 100644 --- a/src/Split/net6.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/net6.0/Numbers/UInt16Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/net6.0/Numbers/UInt32Polyfill.cs b/src/Split/net6.0/Numbers/UInt32Polyfill.cs index abdf707d..9592af7a 100644 --- a/src/Split/net6.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/net6.0/Numbers/UInt32Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/net6.0/Numbers/UInt64Polyfill.cs b/src/Split/net6.0/Numbers/UInt64Polyfill.cs index 1a1bc228..536ba2d9 100644 --- a/src/Split/net6.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/net6.0/Numbers/UInt64Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/net6.0/Numbers/UIntPtrPolyfill.cs b/src/Split/net6.0/Numbers/UIntPtrPolyfill.cs index 2d1485c1..3198624c 100644 --- a/src/Split/net6.0/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net6.0/Numbers/UIntPtrPolyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/net7.0/Numbers/BytePolyfill.cs b/src/Split/net7.0/Numbers/BytePolyfill.cs index 572eab88..c055a56b 100644 --- a/src/Split/net7.0/Numbers/BytePolyfill.cs +++ b/src/Split/net7.0/Numbers/BytePolyfill.cs @@ -26,5 +26,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/net7.0/Numbers/Int128Polyfill.cs b/src/Split/net7.0/Numbers/Int128Polyfill.cs new file mode 100644 index 00000000..b18f70a1 --- /dev/null +++ b/src/Split/net7.0/Numbers/Int128Polyfill.cs @@ -0,0 +1,31 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + extension(Int128) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static Int128 Log10(Int128 value) + { + if (value < Int128.Zero) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return Log10Core((UInt128) value); + } + } + static Int128 Log10Core(UInt128 value) + { + var result = Int128.Zero; + while (value >= 10) + { + value /= 10; + result++; + } + return result; + } +} diff --git a/src/Split/net7.0/Numbers/Int16Polyfill.cs b/src/Split/net7.0/Numbers/Int16Polyfill.cs index c87eac7f..60ac423a 100644 --- a/src/Split/net7.0/Numbers/Int16Polyfill.cs +++ b/src/Split/net7.0/Numbers/Int16Polyfill.cs @@ -25,5 +25,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/net7.0/Numbers/Int32Polyfill.cs b/src/Split/net7.0/Numbers/Int32Polyfill.cs index 9e07d4b5..b61ed0f2 100644 --- a/src/Split/net7.0/Numbers/Int32Polyfill.cs +++ b/src/Split/net7.0/Numbers/Int32Polyfill.cs @@ -25,5 +25,26 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/net7.0/Numbers/Int64Polyfill.cs b/src/Split/net7.0/Numbers/Int64Polyfill.cs index 3c23329b..e1138c11 100644 --- a/src/Split/net7.0/Numbers/Int64Polyfill.cs +++ b/src/Split/net7.0/Numbers/Int64Polyfill.cs @@ -25,5 +25,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/net7.0/Numbers/IntPtrPolyfill.cs b/src/Split/net7.0/Numbers/IntPtrPolyfill.cs index 504c5f8f..bdf79435 100644 --- a/src/Split/net7.0/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net7.0/Numbers/IntPtrPolyfill.cs @@ -25,5 +25,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out nint result) => nint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/net7.0/Numbers/SBytePolyfill.cs b/src/Split/net7.0/Numbers/SBytePolyfill.cs index 488c8b8e..98cc8b12 100644 --- a/src/Split/net7.0/Numbers/SBytePolyfill.cs +++ b/src/Split/net7.0/Numbers/SBytePolyfill.cs @@ -25,5 +25,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/net7.0/Numbers/UInt128Polyfill.cs b/src/Split/net7.0/Numbers/UInt128Polyfill.cs new file mode 100644 index 00000000..c3c33950 --- /dev/null +++ b/src/Split/net7.0/Numbers/UInt128Polyfill.cs @@ -0,0 +1,15 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + extension(UInt128) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static UInt128 Log10(UInt128 value) => + (UInt128) Log10Core(value); + } +} diff --git a/src/Split/net7.0/Numbers/UInt16Polyfill.cs b/src/Split/net7.0/Numbers/UInt16Polyfill.cs index 347c4a42..7683a757 100644 --- a/src/Split/net7.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/net7.0/Numbers/UInt16Polyfill.cs @@ -25,5 +25,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/net7.0/Numbers/UInt32Polyfill.cs b/src/Split/net7.0/Numbers/UInt32Polyfill.cs index fc6b0672..24bdc115 100644 --- a/src/Split/net7.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/net7.0/Numbers/UInt32Polyfill.cs @@ -25,5 +25,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/net7.0/Numbers/UInt64Polyfill.cs b/src/Split/net7.0/Numbers/UInt64Polyfill.cs index 96cf2e21..688e37c3 100644 --- a/src/Split/net7.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/net7.0/Numbers/UInt64Polyfill.cs @@ -25,5 +25,10 @@ public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFor public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/net7.0/Numbers/UIntPtrPolyfill.cs b/src/Split/net7.0/Numbers/UIntPtrPolyfill.cs index fab88512..894a58eb 100644 --- a/src/Split/net7.0/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net7.0/Numbers/UIntPtrPolyfill.cs @@ -25,5 +25,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out nuint result) => nuint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/net8.0/Numbers/BytePolyfill.cs b/src/Split/net8.0/Numbers/BytePolyfill.cs new file mode 100644 index 00000000..f81a30e6 --- /dev/null +++ b/src/Split/net8.0/Numbers/BytePolyfill.cs @@ -0,0 +1,18 @@ +// +#pragma warning disable +#nullable enable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(Byte) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); + } +} diff --git a/src/Split/net8.0/Numbers/Int128Polyfill.cs b/src/Split/net8.0/Numbers/Int128Polyfill.cs new file mode 100644 index 00000000..b18f70a1 --- /dev/null +++ b/src/Split/net8.0/Numbers/Int128Polyfill.cs @@ -0,0 +1,31 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + extension(Int128) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static Int128 Log10(Int128 value) + { + if (value < Int128.Zero) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return Log10Core((UInt128) value); + } + } + static Int128 Log10Core(UInt128 value) + { + var result = Int128.Zero; + while (value >= 10) + { + value /= 10; + result++; + } + return result; + } +} diff --git a/src/Split/net8.0/Numbers/Int16Polyfill.cs b/src/Split/net8.0/Numbers/Int16Polyfill.cs new file mode 100644 index 00000000..ecedff30 --- /dev/null +++ b/src/Split/net8.0/Numbers/Int16Polyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(short) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net8.0/Numbers/Int32Polyfill.cs b/src/Split/net8.0/Numbers/Int32Polyfill.cs new file mode 100644 index 00000000..7409a64d --- /dev/null +++ b/src/Split/net8.0/Numbers/Int32Polyfill.cs @@ -0,0 +1,33 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(int) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; + } +} diff --git a/src/Split/net8.0/Numbers/Int64Polyfill.cs b/src/Split/net8.0/Numbers/Int64Polyfill.cs new file mode 100644 index 00000000..e602de75 --- /dev/null +++ b/src/Split/net8.0/Numbers/Int64Polyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(long) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net8.0/Numbers/IntPtrPolyfill.cs b/src/Split/net8.0/Numbers/IntPtrPolyfill.cs new file mode 100644 index 00000000..57fe93fc --- /dev/null +++ b/src/Split/net8.0/Numbers/IntPtrPolyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(nint) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net8.0/Numbers/SBytePolyfill.cs b/src/Split/net8.0/Numbers/SBytePolyfill.cs new file mode 100644 index 00000000..46cba2c7 --- /dev/null +++ b/src/Split/net8.0/Numbers/SBytePolyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(sbyte) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net8.0/Numbers/UInt128Polyfill.cs b/src/Split/net8.0/Numbers/UInt128Polyfill.cs new file mode 100644 index 00000000..c3c33950 --- /dev/null +++ b/src/Split/net8.0/Numbers/UInt128Polyfill.cs @@ -0,0 +1,15 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + extension(UInt128) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static UInt128 Log10(UInt128 value) => + (UInt128) Log10Core(value); + } +} diff --git a/src/Split/net8.0/Numbers/UInt16Polyfill.cs b/src/Split/net8.0/Numbers/UInt16Polyfill.cs new file mode 100644 index 00000000..23ef736f --- /dev/null +++ b/src/Split/net8.0/Numbers/UInt16Polyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(ushort) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); + } +} diff --git a/src/Split/net8.0/Numbers/UInt32Polyfill.cs b/src/Split/net8.0/Numbers/UInt32Polyfill.cs new file mode 100644 index 00000000..29aab694 --- /dev/null +++ b/src/Split/net8.0/Numbers/UInt32Polyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(uint) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); + } +} diff --git a/src/Split/net8.0/Numbers/UInt64Polyfill.cs b/src/Split/net8.0/Numbers/UInt64Polyfill.cs new file mode 100644 index 00000000..4ac98b2c --- /dev/null +++ b/src/Split/net8.0/Numbers/UInt64Polyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(ulong) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); + } +} diff --git a/src/Split/net8.0/Numbers/UIntPtrPolyfill.cs b/src/Split/net8.0/Numbers/UIntPtrPolyfill.cs new file mode 100644 index 00000000..8eb6c210 --- /dev/null +++ b/src/Split/net8.0/Numbers/UIntPtrPolyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(nuint) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); + } +} diff --git a/src/Split/net9.0/Numbers/BytePolyfill.cs b/src/Split/net9.0/Numbers/BytePolyfill.cs new file mode 100644 index 00000000..f81a30e6 --- /dev/null +++ b/src/Split/net9.0/Numbers/BytePolyfill.cs @@ -0,0 +1,18 @@ +// +#pragma warning disable +#nullable enable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(Byte) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); + } +} diff --git a/src/Split/net9.0/Numbers/Int128Polyfill.cs b/src/Split/net9.0/Numbers/Int128Polyfill.cs new file mode 100644 index 00000000..b18f70a1 --- /dev/null +++ b/src/Split/net9.0/Numbers/Int128Polyfill.cs @@ -0,0 +1,31 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + extension(Int128) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static Int128 Log10(Int128 value) + { + if (value < Int128.Zero) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return Log10Core((UInt128) value); + } + } + static Int128 Log10Core(UInt128 value) + { + var result = Int128.Zero; + while (value >= 10) + { + value /= 10; + result++; + } + return result; + } +} diff --git a/src/Split/net9.0/Numbers/Int16Polyfill.cs b/src/Split/net9.0/Numbers/Int16Polyfill.cs new file mode 100644 index 00000000..ecedff30 --- /dev/null +++ b/src/Split/net9.0/Numbers/Int16Polyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(short) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net9.0/Numbers/Int32Polyfill.cs b/src/Split/net9.0/Numbers/Int32Polyfill.cs new file mode 100644 index 00000000..7409a64d --- /dev/null +++ b/src/Split/net9.0/Numbers/Int32Polyfill.cs @@ -0,0 +1,33 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(int) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; + } +} diff --git a/src/Split/net9.0/Numbers/Int64Polyfill.cs b/src/Split/net9.0/Numbers/Int64Polyfill.cs new file mode 100644 index 00000000..e602de75 --- /dev/null +++ b/src/Split/net9.0/Numbers/Int64Polyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(long) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net9.0/Numbers/IntPtrPolyfill.cs b/src/Split/net9.0/Numbers/IntPtrPolyfill.cs new file mode 100644 index 00000000..57fe93fc --- /dev/null +++ b/src/Split/net9.0/Numbers/IntPtrPolyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(nint) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net9.0/Numbers/SBytePolyfill.cs b/src/Split/net9.0/Numbers/SBytePolyfill.cs new file mode 100644 index 00000000..46cba2c7 --- /dev/null +++ b/src/Split/net9.0/Numbers/SBytePolyfill.cs @@ -0,0 +1,23 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(sbyte) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } + } +} diff --git a/src/Split/net9.0/Numbers/UInt128Polyfill.cs b/src/Split/net9.0/Numbers/UInt128Polyfill.cs new file mode 100644 index 00000000..c3c33950 --- /dev/null +++ b/src/Split/net9.0/Numbers/UInt128Polyfill.cs @@ -0,0 +1,15 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +static partial class Polyfill +{ + extension(UInt128) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static UInt128 Log10(UInt128 value) => + (UInt128) Log10Core(value); + } +} diff --git a/src/Split/net9.0/Numbers/UInt16Polyfill.cs b/src/Split/net9.0/Numbers/UInt16Polyfill.cs new file mode 100644 index 00000000..23ef736f --- /dev/null +++ b/src/Split/net9.0/Numbers/UInt16Polyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(ushort) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); + } +} diff --git a/src/Split/net9.0/Numbers/UInt32Polyfill.cs b/src/Split/net9.0/Numbers/UInt32Polyfill.cs new file mode 100644 index 00000000..29aab694 --- /dev/null +++ b/src/Split/net9.0/Numbers/UInt32Polyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(uint) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); + } +} diff --git a/src/Split/net9.0/Numbers/UInt64Polyfill.cs b/src/Split/net9.0/Numbers/UInt64Polyfill.cs new file mode 100644 index 00000000..4ac98b2c --- /dev/null +++ b/src/Split/net9.0/Numbers/UInt64Polyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(ulong) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); + } +} diff --git a/src/Split/net9.0/Numbers/UIntPtrPolyfill.cs b/src/Split/net9.0/Numbers/UIntPtrPolyfill.cs new file mode 100644 index 00000000..8eb6c210 --- /dev/null +++ b/src/Split/net9.0/Numbers/UIntPtrPolyfill.cs @@ -0,0 +1,17 @@ +// +#pragma warning disable +namespace Polyfills; +using System; +using System.Globalization; +using System.Text; +static partial class Polyfill +{ + extension(nuint) + { + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); + } +} diff --git a/src/Split/netcoreapp2.0/Numbers/BytePolyfill.cs b/src/Split/netcoreapp2.0/Numbers/BytePolyfill.cs index ef3f744e..aec10ff3 100644 --- a/src/Split/netcoreapp2.0/Numbers/BytePolyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/BytePolyfill.cs @@ -46,5 +46,10 @@ public static bool TryParse(ReadOnlySpan s, out byte result) => public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.0/Numbers/Int16Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/Int16Polyfill.cs index 5eb1b384..cd72ce5b 100644 --- a/src/Split/netcoreapp2.0/Numbers/Int16Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/Int16Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.0/Numbers/Int32Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/Int32Polyfill.cs index 549ff189..6b87843d 100644 --- a/src/Split/netcoreapp2.0/Numbers/Int32Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/Int32Polyfill.cs @@ -45,5 +45,26 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/netcoreapp2.0/Numbers/Int64Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/Int64Polyfill.cs index bd33ce0e..682711be 100644 --- a/src/Split/netcoreapp2.0/Numbers/Int64Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/Int64Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.0/Numbers/IntPtrPolyfill.cs b/src/Split/netcoreapp2.0/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/netcoreapp2.0/Numbers/IntPtrPolyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.0/Numbers/SBytePolyfill.cs b/src/Split/netcoreapp2.0/Numbers/SBytePolyfill.cs index 97411565..b2c56485 100644 --- a/src/Split/netcoreapp2.0/Numbers/SBytePolyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/SBytePolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.0/Numbers/UInt16Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/UInt16Polyfill.cs index 34f39f97..1284c8d1 100644 --- a/src/Split/netcoreapp2.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/UInt16Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.0/Numbers/UInt32Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/UInt32Polyfill.cs index 859149be..91159c5e 100644 --- a/src/Split/netcoreapp2.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/UInt32Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.0/Numbers/UInt64Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/UInt64Polyfill.cs index c14bb347..d8fa1789 100644 --- a/src/Split/netcoreapp2.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/UInt64Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.0/Numbers/UIntPtrPolyfill.cs b/src/Split/netcoreapp2.0/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/netcoreapp2.0/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.1/Numbers/BytePolyfill.cs b/src/Split/netcoreapp2.1/Numbers/BytePolyfill.cs index b3235149..30ad6afe 100644 --- a/src/Split/netcoreapp2.1/Numbers/BytePolyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/BytePolyfill.cs @@ -36,5 +36,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.1/Numbers/Int16Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/Int16Polyfill.cs index 7a1f0b7c..f4310059 100644 --- a/src/Split/netcoreapp2.1/Numbers/Int16Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/Int16Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out short result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.1/Numbers/Int32Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/Int32Polyfill.cs index 853dfb51..e455cd66 100644 --- a/src/Split/netcoreapp2.1/Numbers/Int32Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/Int32Polyfill.cs @@ -35,5 +35,26 @@ public static bool TryParse(ReadOnlySpan utf8Text, out int result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/netcoreapp2.1/Numbers/Int64Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/Int64Polyfill.cs index e97be477..15534695 100644 --- a/src/Split/netcoreapp2.1/Numbers/Int64Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/Int64Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out long result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.1/Numbers/IntPtrPolyfill.cs b/src/Split/netcoreapp2.1/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/netcoreapp2.1/Numbers/IntPtrPolyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.1/Numbers/SBytePolyfill.cs b/src/Split/netcoreapp2.1/Numbers/SBytePolyfill.cs index 9085c3ae..d4002463 100644 --- a/src/Split/netcoreapp2.1/Numbers/SBytePolyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/SBytePolyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.1/Numbers/UInt16Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/UInt16Polyfill.cs index 11d4c4ed..b067caa8 100644 --- a/src/Split/netcoreapp2.1/Numbers/UInt16Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/UInt16Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.1/Numbers/UInt32Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/UInt32Polyfill.cs index abdf707d..9592af7a 100644 --- a/src/Split/netcoreapp2.1/Numbers/UInt32Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/UInt32Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.1/Numbers/UInt64Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/UInt64Polyfill.cs index 1a1bc228..536ba2d9 100644 --- a/src/Split/netcoreapp2.1/Numbers/UInt64Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/UInt64Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.1/Numbers/UIntPtrPolyfill.cs b/src/Split/netcoreapp2.1/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/netcoreapp2.1/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.2/Numbers/BytePolyfill.cs b/src/Split/netcoreapp2.2/Numbers/BytePolyfill.cs index b3235149..30ad6afe 100644 --- a/src/Split/netcoreapp2.2/Numbers/BytePolyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/BytePolyfill.cs @@ -36,5 +36,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.2/Numbers/Int16Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/Int16Polyfill.cs index 7a1f0b7c..f4310059 100644 --- a/src/Split/netcoreapp2.2/Numbers/Int16Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/Int16Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out short result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.2/Numbers/Int32Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/Int32Polyfill.cs index 853dfb51..e455cd66 100644 --- a/src/Split/netcoreapp2.2/Numbers/Int32Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/Int32Polyfill.cs @@ -35,5 +35,26 @@ public static bool TryParse(ReadOnlySpan utf8Text, out int result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/netcoreapp2.2/Numbers/Int64Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/Int64Polyfill.cs index e97be477..15534695 100644 --- a/src/Split/netcoreapp2.2/Numbers/Int64Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/Int64Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out long result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.2/Numbers/IntPtrPolyfill.cs b/src/Split/netcoreapp2.2/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/netcoreapp2.2/Numbers/IntPtrPolyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.2/Numbers/SBytePolyfill.cs b/src/Split/netcoreapp2.2/Numbers/SBytePolyfill.cs index 9085c3ae..d4002463 100644 --- a/src/Split/netcoreapp2.2/Numbers/SBytePolyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/SBytePolyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp2.2/Numbers/UInt16Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/UInt16Polyfill.cs index 11d4c4ed..b067caa8 100644 --- a/src/Split/netcoreapp2.2/Numbers/UInt16Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/UInt16Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.2/Numbers/UInt32Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/UInt32Polyfill.cs index abdf707d..9592af7a 100644 --- a/src/Split/netcoreapp2.2/Numbers/UInt32Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/UInt32Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.2/Numbers/UInt64Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/UInt64Polyfill.cs index 1a1bc228..536ba2d9 100644 --- a/src/Split/netcoreapp2.2/Numbers/UInt64Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/UInt64Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/netcoreapp2.2/Numbers/UIntPtrPolyfill.cs b/src/Split/netcoreapp2.2/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/netcoreapp2.2/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/netcoreapp3.0/Numbers/BytePolyfill.cs b/src/Split/netcoreapp3.0/Numbers/BytePolyfill.cs index b3235149..30ad6afe 100644 --- a/src/Split/netcoreapp3.0/Numbers/BytePolyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/BytePolyfill.cs @@ -36,5 +36,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/netcoreapp3.0/Numbers/Int16Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/Int16Polyfill.cs index 7a1f0b7c..f4310059 100644 --- a/src/Split/netcoreapp3.0/Numbers/Int16Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/Int16Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out short result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp3.0/Numbers/Int32Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/Int32Polyfill.cs index 853dfb51..e455cd66 100644 --- a/src/Split/netcoreapp3.0/Numbers/Int32Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/Int32Polyfill.cs @@ -35,5 +35,26 @@ public static bool TryParse(ReadOnlySpan utf8Text, out int result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/netcoreapp3.0/Numbers/Int64Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/Int64Polyfill.cs index e97be477..15534695 100644 --- a/src/Split/netcoreapp3.0/Numbers/Int64Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/Int64Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out long result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp3.0/Numbers/IntPtrPolyfill.cs b/src/Split/netcoreapp3.0/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/netcoreapp3.0/Numbers/IntPtrPolyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp3.0/Numbers/SBytePolyfill.cs b/src/Split/netcoreapp3.0/Numbers/SBytePolyfill.cs index 9085c3ae..d4002463 100644 --- a/src/Split/netcoreapp3.0/Numbers/SBytePolyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/SBytePolyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp3.0/Numbers/UInt16Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/UInt16Polyfill.cs index 11d4c4ed..b067caa8 100644 --- a/src/Split/netcoreapp3.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/UInt16Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/netcoreapp3.0/Numbers/UInt32Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/UInt32Polyfill.cs index abdf707d..9592af7a 100644 --- a/src/Split/netcoreapp3.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/UInt32Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/netcoreapp3.0/Numbers/UInt64Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/UInt64Polyfill.cs index 1a1bc228..536ba2d9 100644 --- a/src/Split/netcoreapp3.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/UInt64Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/netcoreapp3.0/Numbers/UIntPtrPolyfill.cs b/src/Split/netcoreapp3.0/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/netcoreapp3.0/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/netcoreapp3.1/Numbers/BytePolyfill.cs b/src/Split/netcoreapp3.1/Numbers/BytePolyfill.cs index b3235149..30ad6afe 100644 --- a/src/Split/netcoreapp3.1/Numbers/BytePolyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/BytePolyfill.cs @@ -36,5 +36,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/netcoreapp3.1/Numbers/Int16Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/Int16Polyfill.cs index 7a1f0b7c..f4310059 100644 --- a/src/Split/netcoreapp3.1/Numbers/Int16Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/Int16Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out short result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp3.1/Numbers/Int32Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/Int32Polyfill.cs index 853dfb51..e455cd66 100644 --- a/src/Split/netcoreapp3.1/Numbers/Int32Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/Int32Polyfill.cs @@ -35,5 +35,26 @@ public static bool TryParse(ReadOnlySpan utf8Text, out int result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/netcoreapp3.1/Numbers/Int64Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/Int64Polyfill.cs index e97be477..15534695 100644 --- a/src/Split/netcoreapp3.1/Numbers/Int64Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/Int64Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out long result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp3.1/Numbers/IntPtrPolyfill.cs b/src/Split/netcoreapp3.1/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/netcoreapp3.1/Numbers/IntPtrPolyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp3.1/Numbers/SBytePolyfill.cs b/src/Split/netcoreapp3.1/Numbers/SBytePolyfill.cs index 9085c3ae..d4002463 100644 --- a/src/Split/netcoreapp3.1/Numbers/SBytePolyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/SBytePolyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/netcoreapp3.1/Numbers/UInt16Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/UInt16Polyfill.cs index 11d4c4ed..b067caa8 100644 --- a/src/Split/netcoreapp3.1/Numbers/UInt16Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/UInt16Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/netcoreapp3.1/Numbers/UInt32Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/UInt32Polyfill.cs index abdf707d..9592af7a 100644 --- a/src/Split/netcoreapp3.1/Numbers/UInt32Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/UInt32Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/netcoreapp3.1/Numbers/UInt64Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/UInt64Polyfill.cs index 1a1bc228..536ba2d9 100644 --- a/src/Split/netcoreapp3.1/Numbers/UInt64Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/UInt64Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/netcoreapp3.1/Numbers/UIntPtrPolyfill.cs b/src/Split/netcoreapp3.1/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/netcoreapp3.1/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/netstandard2.0/Numbers/BytePolyfill.cs b/src/Split/netstandard2.0/Numbers/BytePolyfill.cs index ef3f744e..aec10ff3 100644 --- a/src/Split/netstandard2.0/Numbers/BytePolyfill.cs +++ b/src/Split/netstandard2.0/Numbers/BytePolyfill.cs @@ -46,5 +46,10 @@ public static bool TryParse(ReadOnlySpan s, out byte result) => public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/netstandard2.0/Numbers/Int16Polyfill.cs b/src/Split/netstandard2.0/Numbers/Int16Polyfill.cs index 5eb1b384..cd72ce5b 100644 --- a/src/Split/netstandard2.0/Numbers/Int16Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/Int16Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/netstandard2.0/Numbers/Int32Polyfill.cs b/src/Split/netstandard2.0/Numbers/Int32Polyfill.cs index 549ff189..6b87843d 100644 --- a/src/Split/netstandard2.0/Numbers/Int32Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/Int32Polyfill.cs @@ -45,5 +45,26 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/netstandard2.0/Numbers/Int64Polyfill.cs b/src/Split/netstandard2.0/Numbers/Int64Polyfill.cs index bd33ce0e..682711be 100644 --- a/src/Split/netstandard2.0/Numbers/Int64Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/Int64Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/netstandard2.0/Numbers/IntPtrPolyfill.cs b/src/Split/netstandard2.0/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/netstandard2.0/Numbers/IntPtrPolyfill.cs +++ b/src/Split/netstandard2.0/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/netstandard2.0/Numbers/SBytePolyfill.cs b/src/Split/netstandard2.0/Numbers/SBytePolyfill.cs index 97411565..b2c56485 100644 --- a/src/Split/netstandard2.0/Numbers/SBytePolyfill.cs +++ b/src/Split/netstandard2.0/Numbers/SBytePolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/netstandard2.0/Numbers/UInt16Polyfill.cs b/src/Split/netstandard2.0/Numbers/UInt16Polyfill.cs index 34f39f97..1284c8d1 100644 --- a/src/Split/netstandard2.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/UInt16Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/netstandard2.0/Numbers/UInt32Polyfill.cs b/src/Split/netstandard2.0/Numbers/UInt32Polyfill.cs index 859149be..91159c5e 100644 --- a/src/Split/netstandard2.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/UInt32Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/netstandard2.0/Numbers/UInt64Polyfill.cs b/src/Split/netstandard2.0/Numbers/UInt64Polyfill.cs index c14bb347..d8fa1789 100644 --- a/src/Split/netstandard2.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/UInt64Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/netstandard2.0/Numbers/UIntPtrPolyfill.cs b/src/Split/netstandard2.0/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/netstandard2.0/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/netstandard2.0/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/netstandard2.1/Numbers/BytePolyfill.cs b/src/Split/netstandard2.1/Numbers/BytePolyfill.cs index b3235149..30ad6afe 100644 --- a/src/Split/netstandard2.1/Numbers/BytePolyfill.cs +++ b/src/Split/netstandard2.1/Numbers/BytePolyfill.cs @@ -36,5 +36,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFo public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/netstandard2.1/Numbers/Int16Polyfill.cs b/src/Split/netstandard2.1/Numbers/Int16Polyfill.cs index 7a1f0b7c..f4310059 100644 --- a/src/Split/netstandard2.1/Numbers/Int16Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/Int16Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out short result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/netstandard2.1/Numbers/Int32Polyfill.cs b/src/Split/netstandard2.1/Numbers/Int32Polyfill.cs index 853dfb51..e455cd66 100644 --- a/src/Split/netstandard2.1/Numbers/Int32Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/Int32Polyfill.cs @@ -35,5 +35,26 @@ public static bool TryParse(ReadOnlySpan utf8Text, out int result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/netstandard2.1/Numbers/Int64Polyfill.cs b/src/Split/netstandard2.1/Numbers/Int64Polyfill.cs index e97be477..15534695 100644 --- a/src/Split/netstandard2.1/Numbers/Int64Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/Int64Polyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out long result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/netstandard2.1/Numbers/IntPtrPolyfill.cs b/src/Split/netstandard2.1/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/netstandard2.1/Numbers/IntPtrPolyfill.cs +++ b/src/Split/netstandard2.1/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/netstandard2.1/Numbers/SBytePolyfill.cs b/src/Split/netstandard2.1/Numbers/SBytePolyfill.cs index 9085c3ae..d4002463 100644 --- a/src/Split/netstandard2.1/Numbers/SBytePolyfill.cs +++ b/src/Split/netstandard2.1/Numbers/SBytePolyfill.cs @@ -35,5 +35,16 @@ public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/netstandard2.1/Numbers/UInt16Polyfill.cs b/src/Split/netstandard2.1/Numbers/UInt16Polyfill.cs index 11d4c4ed..b067caa8 100644 --- a/src/Split/netstandard2.1/Numbers/UInt16Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/UInt16Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/netstandard2.1/Numbers/UInt32Polyfill.cs b/src/Split/netstandard2.1/Numbers/UInt32Polyfill.cs index abdf707d..9592af7a 100644 --- a/src/Split/netstandard2.1/Numbers/UInt32Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/UInt32Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/netstandard2.1/Numbers/UInt64Polyfill.cs b/src/Split/netstandard2.1/Numbers/UInt64Polyfill.cs index 1a1bc228..536ba2d9 100644 --- a/src/Split/netstandard2.1/Numbers/UInt64Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/UInt64Polyfill.cs @@ -35,5 +35,10 @@ public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/netstandard2.1/Numbers/UIntPtrPolyfill.cs b/src/Split/netstandard2.1/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/netstandard2.1/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/netstandard2.1/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Split/uap10.0/Numbers/BytePolyfill.cs b/src/Split/uap10.0/Numbers/BytePolyfill.cs index ef3f744e..aec10ff3 100644 --- a/src/Split/uap10.0/Numbers/BytePolyfill.cs +++ b/src/Split/uap10.0/Numbers/BytePolyfill.cs @@ -46,5 +46,10 @@ public static bool TryParse(ReadOnlySpan s, out byte result) => public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static byte Log10(byte value) => + (byte) Log10Core(value); } } diff --git a/src/Split/uap10.0/Numbers/Int16Polyfill.cs b/src/Split/uap10.0/Numbers/Int16Polyfill.cs index 5eb1b384..cd72ce5b 100644 --- a/src/Split/uap10.0/Numbers/Int16Polyfill.cs +++ b/src/Split/uap10.0/Numbers/Int16Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static short Log10(short value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (short) Log10Core((ulong) value); + } } } diff --git a/src/Split/uap10.0/Numbers/Int32Polyfill.cs b/src/Split/uap10.0/Numbers/Int32Polyfill.cs index 549ff189..6b87843d 100644 --- a/src/Split/uap10.0/Numbers/Int32Polyfill.cs +++ b/src/Split/uap10.0/Numbers/Int32Polyfill.cs @@ -45,5 +45,26 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static int Log10(int value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (int) Log10Core((ulong) value); + } + } + static int Log10Core(ulong value) + { + var result = 0; + while (value >= 10) + { + value /= 10; + result++; + } + return result; } } diff --git a/src/Split/uap10.0/Numbers/Int64Polyfill.cs b/src/Split/uap10.0/Numbers/Int64Polyfill.cs index bd33ce0e..682711be 100644 --- a/src/Split/uap10.0/Numbers/Int64Polyfill.cs +++ b/src/Split/uap10.0/Numbers/Int64Polyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static long Log10(long value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (long) Log10Core((ulong) value); + } } } diff --git a/src/Split/uap10.0/Numbers/IntPtrPolyfill.cs b/src/Split/uap10.0/Numbers/IntPtrPolyfill.cs index 04a69769..fafe1b2b 100644 --- a/src/Split/uap10.0/Numbers/IntPtrPolyfill.cs +++ b/src/Split/uap10.0/Numbers/IntPtrPolyfill.cs @@ -75,5 +75,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nint result) => nint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nint Log10(nint value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (nint) Log10Core((ulong) value); + } } } diff --git a/src/Split/uap10.0/Numbers/SBytePolyfill.cs b/src/Split/uap10.0/Numbers/SBytePolyfill.cs index 97411565..b2c56485 100644 --- a/src/Split/uap10.0/Numbers/SBytePolyfill.cs +++ b/src/Split/uap10.0/Numbers/SBytePolyfill.cs @@ -45,5 +45,16 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static sbyte Log10(sbyte value) + { + if (value < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, "value must be a non-negative number."); + } + return (sbyte) Log10Core((ulong) value); + } } } diff --git a/src/Split/uap10.0/Numbers/UInt16Polyfill.cs b/src/Split/uap10.0/Numbers/UInt16Polyfill.cs index 34f39f97..1284c8d1 100644 --- a/src/Split/uap10.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/uap10.0/Numbers/UInt16Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ushort Log10(ushort value) => + (ushort) Log10Core(value); } } diff --git a/src/Split/uap10.0/Numbers/UInt32Polyfill.cs b/src/Split/uap10.0/Numbers/UInt32Polyfill.cs index 859149be..91159c5e 100644 --- a/src/Split/uap10.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/uap10.0/Numbers/UInt32Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static uint Log10(uint value) => + (uint) Log10Core(value); } } diff --git a/src/Split/uap10.0/Numbers/UInt64Polyfill.cs b/src/Split/uap10.0/Numbers/UInt64Polyfill.cs index c14bb347..d8fa1789 100644 --- a/src/Split/uap10.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/uap10.0/Numbers/UInt64Polyfill.cs @@ -45,5 +45,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static ulong Log10(ulong value) => + (ulong) Log10Core(value); } } diff --git a/src/Split/uap10.0/Numbers/UIntPtrPolyfill.cs b/src/Split/uap10.0/Numbers/UIntPtrPolyfill.cs index 09ac5e3e..4b29454b 100644 --- a/src/Split/uap10.0/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/uap10.0/Numbers/UIntPtrPolyfill.cs @@ -75,5 +75,10 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out nuint result) => nuint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif + /// + /// Computes the base-10 logarithm of a value. + /// + public static nuint Log10(nuint value) => + (nuint) Log10Core(value); } } diff --git a/src/Tests/PolyfillTests_Log10.cs b/src/Tests/PolyfillTests_Log10.cs new file mode 100644 index 00000000..efe56454 --- /dev/null +++ b/src/Tests/PolyfillTests_Log10.cs @@ -0,0 +1,83 @@ +partial class PolyfillTests +{ + [Test] + [Arguments(0, 0)] + [Arguments(1, 0)] + [Arguments(9, 0)] + [Arguments(10, 1)] + [Arguments(11, 1)] + [Arguments(99, 1)] + [Arguments(100, 2)] + [Arguments(999, 2)] + [Arguments(1000, 3)] + [Arguments(int.MaxValue, 9)] + public async Task Int32_Log10(int value, int expected) => + await Assert.That(int.Log10(value)).IsEqualTo(expected); + + [Test] + public async Task Log10_Unsigned() + { + await Assert.That(byte.Log10(0)).IsEqualTo((byte) 0); + await Assert.That(byte.Log10(9)).IsEqualTo((byte) 0); + await Assert.That(byte.Log10(byte.MaxValue)).IsEqualTo((byte) 2); + await Assert.That(ushort.Log10(ushort.MaxValue)).IsEqualTo((ushort) 4); + await Assert.That(uint.Log10(uint.MaxValue)).IsEqualTo(9u); + await Assert.That(ulong.Log10(ulong.MaxValue)).IsEqualTo(19ul); + await Assert.That(nuint.Log10(1000)).IsEqualTo((nuint) 3); + } + + [Test] + public async Task Log10_Signed() + { + await Assert.That(sbyte.Log10(sbyte.MaxValue)).IsEqualTo((sbyte) 2); + await Assert.That(short.Log10(short.MaxValue)).IsEqualTo((short) 4); + await Assert.That(long.Log10(long.MaxValue)).IsEqualTo(18L); + await Assert.That(nint.Log10(1000)).IsEqualTo((nint) 3); + } + + [Test] + public async Task Log10_Negative_Throws() + { + await Assert.That(() => { sbyte.Log10(-1); }).Throws(); + await Assert.That(() => { short.Log10(-1); }).Throws(); + await Assert.That(() => { int.Log10(-1); }).Throws(); + await Assert.That(() => { int.Log10(int.MinValue); }).Throws(); + await Assert.That(() => { long.Log10(-1); }).Throws(); + await Assert.That(() => { nint.Log10(-1); }).Throws(); + } + + // every power of ten, and the value either side of it, is where an off by one shows up + [Test] + public async Task Int64_Log10_PowersOfTen() + { + var power = 1L; + for (var exponent = 0; exponent < 19; exponent++) + { + await Assert.That(long.Log10(power)).IsEqualTo((long) exponent); + if (power > 1) + { + await Assert.That(long.Log10(power - 1)).IsEqualTo((long) (exponent - 1)); + } + + if (exponent < 18) + { + await Assert.That(long.Log10(power + 1)).IsEqualTo((long) exponent); + power *= 10; + } + } + } + +#if NET7_0_OR_GREATER + [Test] + public async Task Int128_Log10() + { + await Assert.That(Int128.Log10(Int128.Zero)).IsEqualTo(Int128.Zero); + await Assert.That(Int128.Log10(999)).IsEqualTo((Int128) 2); + await Assert.That(Int128.Log10(1000)).IsEqualTo((Int128) 3); + await Assert.That(Int128.Log10(Int128.MaxValue)).IsEqualTo((Int128) 38); + await Assert.That(UInt128.Log10(UInt128.Zero)).IsEqualTo(UInt128.Zero); + await Assert.That(UInt128.Log10(UInt128.MaxValue)).IsEqualTo((UInt128) 38); + await Assert.That(() => { Int128.Log10(Int128.NegativeOne); }).Throws(); + } +#endif +}