[API Proposal]: Add Math.DivRem and Math.IEEEDivRem for floating point types
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Background and motivation
There is currently no convenient, standard API to obtain the **quotient** when using `operator%` or `Math.IEEERemainder` for floating‑point values. This forces callers to reimplement quotient recovery or rely on error-prone ad hoc code. Adding `Math.DivRem` and `Math.IEEEDivRem` overloads for `float`/`double` that return both **Quotient** and **Remainder** would make intent explicit, reduce potential bugs and improves performance.
### API Proposal
```csharp
namespace System;
partial class Math
{
public static (double Quotient, double Remainder) DivRem(double dividend, double divisor);
public static (float Quotient, float Remainder) DivRem(float dividend, float divisor);
public static (double Quotient, double Remainder) IEEEDivRem(double dividend, double divisor);
public static (float Quotient, float Remainder) IEEEDivRem(float dividend, float divisor);
}
```
### API Usage
```csharp
Console.WriteLine(Math.DivRem(1.0, 0.1).Remainder == 1.0 % 0.1); // true
Console.WriteLine(Math.DivRem(1.0, 0.1).Quotient == 9.0); // true
```
### Alternative Designs
_No response_
### Risks
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.