Skip to content

Math.Clamp is missing documentation on its thrown exception for degenerate ranges #10677

Open
@rjgotten

Description

@rjgotten

Type of issue

Code doesn't work

Description

Math.Clamp is currently documented as returning, in order of precedence:

  1. value - where min <= value <= max;
  2. min - where value < min; or
  3. max - where max < value.

This means it should support degenerate ranges such as Math.Clamp(10, 0, -2) and result in the 2nd case, returning 0.

This is actually not how the method is implemented.
It expressly checks for min <= max and throws an ArgumentException in cases that don't fit this constraint.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.math.clamp?view=net-8.0

Content source URL

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

Document Version Independent Id

8e48c3bd-8e68-e4c7-167c-07efd236a06f

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.Runtimehelp wantedGood for community contributors to help [up-for-grabs]

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions