-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary operations for AnyInt
hierarchy
#31
Comments
AnyInt
hierarchy
We should also introduce binary operations using the |
Here is the list of /** Adds the [other] integer to this one. */
operator fun Int.plus(other: AnyInt): Int
operator fun AnyInt.plus(other: Int): Int
operator fun AnyInt.plus(other: AnyInt): Int |
Here's the list of /** Subtracts the [other] integer from this one. */
operator fun Int.minus(other: AnyInt): Int
operator fun AnyInt.minus(other: Int): Int
operator fun AnyInt.minus(other: AnyInt): Int |
Here's the list of /** Multiplies this integer by the [other] one. */
operator fun Int.times(other: AnyInt): Int
operator fun AnyInt.times(other: Int): Int
operator fun AnyInt.times(other: AnyInt): Int |
Here's the list of /**
* Divides this integer by the [other] one, truncating the result to an integer
* that is closer to [zero][ZeroInt].
*/
operator fun Int.div(other: NonZeroInt): Int
operator fun AnyInt.div(other: NonZeroInt): Int
operator fun PositiveInt.div(other: StrictlyPositiveInt): PositiveInt
operator fun PositiveInt.div(other: StrictlyNegativeInt): NegativeInt
operator fun NegativeInt.div(other: StrictlyPositiveInt): NegativeInt
operator fun NegativeInt.div(other: StrictlyNegativeInt): PositiveInt |
Here's the list of /**
* Calculates the remainder of truncating division of this integer by the
* [other] one.
*/
operator fun Int.rem(other: NonZeroInt): Int
operator fun AnyInt.rem(other: NonZeroInt): Int
operator fun PositiveInt.rem(other: NonZeroInt): PositiveInt
operator fun NegativeInt.rem(other: NonZeroInt): NegativeInt |
Those changes will not be implemented according to our design principles. |
Implementing those changes will simplify the usage of the val x: NonZeroInt = NonZeroInt.random()
val y: PositiveInt = PositiveInt.random()
var result: Int
// before
result = x.toInt() + 1
result = 1 + x.toInt()
result = x.toInt() + y.toInt()
// after
result = x + 1
result = 1 + x
result = x + y |
This operation was converted to a member function and now returns an AnyInt instead of an Int.
Description
Implement binary operations for the
AnyInt
hierarchy.Checklist
plus
operations.minus
operations.times
operations.div
operations.rem
operations.Unreleased
section in changelog.The text was updated successfully, but these errors were encountered: