Skip to content

Conversation

@shethaadit
Copy link
Contributor

@shethaadit shethaadit commented Nov 27, 2024

Summary

Problem

The existing documentation only describes unchecked arithmetic operators, which do not throw exceptions on overflow, potentially leading to unintended behavior. Checked arithmetic operators were missing, and there was no guidance on handling overflow scenarios effectively.

Solution

This update introduces a new section on checked arithmetic operators in F#. It includes:

  • A comparison of checked and unchecked operators.
  • Practical examples demonstrating how to use checked operators from the Microsoft.FSharp.Core.Operators.Checked module.
  • A try...with example for handling System.OverflowException.
  • Guidance for choosing between checked and unchecked arithmetic based on use case.

Impact

This change improves the usability of the documentation by providing comprehensive guidance for developers who need overflow-safe arithmetic operations.

Fixes #41859


Internal previews

📄 File 🔗 Preview link
docs/fsharp/language-reference/symbol-and-operator-reference/arithmetic-operators.md Arithmetic Operators

@dotnetrepoman dotnetrepoman bot added this to the November 2024 milestone Nov 27, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates PR is created by someone from the .NET community. label Nov 27, 2024
@shethaadit
Copy link
Contributor Author

Hi @T-Gro, since I am learning F#, Really appreciate if you can apply suggestions on the commit? :)

@T-Gro
Copy link
Member

T-Gro commented Dec 4, 2024

Hi @T-Gro, since I am learning F#, Really appreciate if you can apply suggestions on the commit? :)

The suggestions done now are good, thank you for incorporating that.

I think it now makes it very clear what the default is and also when overflow+underflow can happen.

Good job.

@shethaadit
Copy link
Contributor Author

Hi @BillWagner / @KathleenDollard, could you please have a look at the PR and merge?

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM @shethaadit

I'll :shipit: now.

@BillWagner BillWagner merged commit ab565f2 into dotnet:main Dec 5, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community. dotnet-fsharp/svc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

checked arithmetic in F#

3 participants