dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
725 stars 1.56k forks source link

Small error in BigInteger(Int64) constructor example #10346

Open clivetooth opened 2 months ago

clivetooth commented 2 months ago

Type of issue

Other (describe below)

Description

The code has: long[] longs = { Int64.MinValue, -10534, -189, 0, 17, 113439, Int64.MaxValue };

But the output has: // The example displays the following output: // -2147483648 = -2147483648: True // -10534 = -10534: True // -189 = -189: True // 0 = 0: True // 17 = 17: True // 113439 = 113439: True // 2147483647 = 2147483647: True

The values in the output are Int32.MinValue and int32.MaxValue, not Int64.MinValue and int64.MaxValue.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.numerics.biginteger.-ctor?view=netframework-4.0

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Numerics/BigInteger.xml

Document Version Independent Id

8c6625e5-760b-a2f4-0fa8-bad34c2d0aaa

Article author

@dotnet-bot

dotnet-issue-labeler[bot] commented 2 months ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

dotnet-issue-labeler[bot] commented 2 months ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

krwq commented 1 month ago

@clivetooth can you please clarify where are you hitting this? I've run following code on .NET 8:

using System.Numerics;

long[] longs = { Int64.MinValue, -10534, -189, 0, 17, 113439,
Int64.MaxValue };

foreach (var x in longs)
{
    BigInteger bigInt = new BigInteger(x);
    Console.WriteLine(bigInt.ToString());
}

and it prints:

-9223372036854775808
-10534
-189
0
17
113439
9223372036854775807
clivetooth commented 1 month ago

Part of my report seems to have got lost. (Possibly due to me doing something wrong.) Anyway, I was trying to report an error in the documentation of the BigInteger(long) constructor, which I reproduce here: = = = = = .NET 9 and other versions BigInteger(Int64) Initializes a new instance of the BigInteger structure using a 64-bit signed integer value.

C#

public BigInteger (long value); Parameters value Int64 A 64-bit signed integer.

Examples The following example calls the BigInteger(Int64) constructor to instantiate BigInteger values from an array of 64-bit integers. It also uses implicit conversion to assign each 64-bit integer value to a BigInteger variable. It then compares the two values to establish that the resulting BigInteger values are the same.

C#

long[] longs = { Int64.MinValue, -10534, -189, 0, 17, 113439, Int64.MaxValue }; BigInteger constructed, assigned;

foreach (long number in longs) { constructed = new BigInteger(number); assigned = number; Console.WriteLine("{0} = {1}: {2}", constructed, assigned, constructed.Equals(assigned)); } // The example displays the following output: // -2147483648 = -2147483648: True // -10534 = -10534: True // -189 = -189: True // 0 = 0: True // 17 = 17: True // 113439 = 113439: True // 2147483647 = 2147483647: True = = = = =