dotnet-api-docs icon indicating copy to clipboard operation
dotnet-api-docs copied to clipboard

Small error in BigInteger(Int64) constructor example

Open clivetooth opened this issue 1 year ago • 4 comments

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

clivetooth avatar Aug 30 '24 21:08 clivetooth

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.

ghost avatar Aug 30 '24 21:08 ghost

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.

ghost avatar Aug 30 '24 21:08 ghost

@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

krwq avatar Sep 05 '24 11:09 krwq

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 = = = = =

clivetooth avatar Sep 05 '24 12:09 clivetooth

Tagging subscribers to this area: @dotnet/area-system-numerics

Contributions are welcome, this is an obvious copy/paste error or similar, so a simple PR that does the following should be sufficient

  // The example displays the following output:
- // -2147483648 = -2147483648: True
+ // -9223372036854775808 = -9223372036854775808: True
  // -10534 = -10534: True
  // -189 = -189: True
  // 0 = 0: True
  // 17 = 17: True
  // 113439 = 113439: True
- // 2147483647 = 2147483647: True
+ // 9223372036854775807 = 9223372036854775807: True

tannergooding avatar Nov 19 '24 17:11 tannergooding