Skip to content

Possibly flawed algorithm #41596

Open
Open
@gggustafson

Description

@gggustafson

Type of issue

Other (describe below)

Description

In the "namespace IncludeTag" example, I do not believe that:

 if ((a == int.MaxValue && b > 0) || 
        (b == int.MaxValue && a > 0))

is the correct algorithm. For integers I suggest:

const int MAXINT_DIV_10 = int.MaxValue / 10;
const int MAXINT_MOD_10 = int.MaxValue % 10;

if ( !( ( a < MAXINT_DIV_10 ) ||
   ( ( a = MAXINT_DIV_10 ) && 
   ( b <= MAXINT_MOD_10 ) ) ) )
{
    throw new System.OverflowException ( );
}
 
return ( a + b );

For doubles, the algorithm is somewhat the same.

Aside: How do I get indentation to work?

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/examples

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/xmldoc/examples.md

Document Version Independent Id

33d9f302-a3aa-a165-ec64-a4382feb093e

Article author

@BillWagner

Metadata

  • ID: 60a08067-b91f-3c9a-0569-30d098089990
  • Service: dotnet-csharp
  • Sub-service: lang-reference

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions