Skip to content

Add __round__ for .NET integer types - #2077

Open
slozier wants to merge 2 commits into
IronLanguages:mainfrom
slozier:round
Open

Add __round__ for .NET integer types#2077
slozier wants to merge 2 commits into
IronLanguages:mainfrom
slozier:round

Conversation

@slozier

@slozier slozier commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Adds a __round__ implementation for the .NET integer types (e.g. System.Int16, System.UInt16, etc.) with the following semantics:

  • Calling __round__ without an ndigits argument always returns a Python int.
  • Calling with an ndigits argument will attempt to preserve the type. In the case where an overflow would occur I chose widen to a Python int instead of overflowing which is consistent with the other operators we implement.

Note that numpy behaves similarly except that it overflows instead of widening. I think I would have preferred this behaviour but chose to be consistent with the other operators.

Resolves #1977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

round fails when encountering a Single

1 participant