You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
📝 Details
The Rounding-Modes API (in the Math library) currently includes:
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
The last two options are different from the first two options only when dealing with signed input.
However, throughout the codebase, rounding-modes are used strictly for unsigned input.
Hence as it stands, the last two options are redundant in the current version.
My initial motivation was adding a Nearest mode, which for non-negative (unsigned) input stands for:
Round down (towards zero) any value with remainder < 0.5
Round up (towards infinity) any value with remainder >= 0.5
Adding this new mode is questionable (and a lot more complicated) when the enum at hand is "seemingly" implemented to support both signed and unsigned input. By getting rid of what appears to be redundant (unused) API, it might make it easier to add this new mode. But even regardless of this new mode, it makes sense to clean-up the unused part of this API.
UPDATE:
Note that a more complete fix might actually be to get rid of the Rounding-Mode API altogether, and split each function which takes it as input into two functions - a floor function and a ceil function.
Reason being - it would save gas for the caller:
For the floor functions, checking the rounding mode AND calculating the additional info will be omitted
For the ceil functions, checking the rounding mode will be omitted
Of course, with 4 different rounding modes, this might "bloat" the Math library's code.
But if you choose to accept my proposal and reduce it to 2 different rounding modes, then taking it one step forward and splitting each one of the associated functions into a pair of functions might seem like an option for you to consider.
The text was updated successfully, but these errors were encountered:
🧐 Motivation
📝 Details
The Rounding-Modes API (in the Math library) currently includes:
The last two options are different from the first two options only when dealing with signed input.
However, throughout the codebase, rounding-modes are used strictly for unsigned input.
Hence as it stands, the last two options are redundant in the current version.
My initial motivation was adding a
Nearest
mode, which for non-negative (unsigned) input stands for:Adding this new mode is questionable (and a lot more complicated) when the enum at hand is "seemingly" implemented to support both signed and unsigned input. By getting rid of what appears to be redundant (unused) API, it might make it easier to add this new mode. But even regardless of this new mode, it makes sense to clean-up the unused part of this API.
UPDATE:
Note that a more complete fix might actually be to get rid of the Rounding-Mode API altogether, and split each function which takes it as input into two functions - a floor function and a ceil function.
Reason being - it would save gas for the caller:
Of course, with 4 different rounding modes, this might "bloat" the Math library's code.
But if you choose to accept my proposal and reduce it to 2 different rounding modes, then taking it one step forward and splitting each one of the associated functions into a pair of functions might seem like an option for you to consider.
The text was updated successfully, but these errors were encountered: