Floor division and remainder for numeric types KT-26234

- floorDiv/mod for unsigned types
- floorDiv/mod for signed types
- mod for floating point types

- mod return type: same as divisor for integer types

- Update JS API dump
- Avoid triggering division overflow in tests due to K/N
- Workaround failing test in JS-legacy
This commit is contained in:
Ilya Gorbunov
2021-02-20 04:24:45 +03:00
parent 284e6f5bb3
commit 50d4979531
14 changed files with 1308 additions and 42 deletions
@@ -135,6 +135,32 @@ public value class UByte @PublishedApi internal constructor(@PublishedApi intern
@kotlin.internal.InlineOnly
public inline operator fun rem(other: ULong): ULong = this.toULong().rem(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UByte): UInt = this.toUInt().floorDiv(other.toUInt())
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UShort): UInt = this.toUInt().floorDiv(other.toUInt())
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UInt): UInt = this.toUInt().floorDiv(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: ULong): ULong = this.toULong().floorDiv(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UByte): UByte = this.toUInt().mod(other.toUInt()).toUByte()
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UShort): UShort = this.toUInt().mod(other.toUInt()).toUShort()
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UInt): UInt = this.toUInt().mod(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: ULong): ULong = this.toULong().mod(other)
/** Increments this value. */
@kotlin.internal.InlineOnly
public inline operator fun inc(): UByte = UByte(data.inc())
@@ -135,6 +135,32 @@ public value class UInt @PublishedApi internal constructor(@PublishedApi interna
@kotlin.internal.InlineOnly
public inline operator fun rem(other: ULong): ULong = this.toULong().rem(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UByte): UInt = this.floorDiv(other.toUInt())
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UShort): UInt = this.floorDiv(other.toUInt())
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UInt): UInt = div(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: ULong): ULong = this.toULong().floorDiv(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UByte): UByte = this.mod(other.toUInt()).toUByte()
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UShort): UShort = this.mod(other.toUInt()).toUShort()
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UInt): UInt = rem(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: ULong): ULong = this.toULong().mod(other)
/** Increments this value. */
@kotlin.internal.InlineOnly
public inline operator fun inc(): UInt = UInt(data.inc())
@@ -135,6 +135,32 @@ public value class ULong @PublishedApi internal constructor(@PublishedApi intern
@kotlin.internal.InlineOnly
public inline operator fun rem(other: ULong): ULong = ulongRemainder(this, other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UByte): ULong = this.floorDiv(other.toULong())
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UShort): ULong = this.floorDiv(other.toULong())
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UInt): ULong = this.floorDiv(other.toULong())
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: ULong): ULong = div(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UByte): UByte = this.mod(other.toULong()).toUByte()
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UShort): UShort = this.mod(other.toULong()).toUShort()
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UInt): UInt = this.mod(other.toULong()).toUInt()
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: ULong): ULong = rem(other)
/** Increments this value. */
@kotlin.internal.InlineOnly
public inline operator fun inc(): ULong = ULong(data.inc())
@@ -135,6 +135,32 @@ public value class UShort @PublishedApi internal constructor(@PublishedApi inter
@kotlin.internal.InlineOnly
public inline operator fun rem(other: ULong): ULong = this.toULong().rem(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UByte): UInt = this.toUInt().floorDiv(other.toUInt())
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UShort): UInt = this.toUInt().floorDiv(other.toUInt())
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: UInt): UInt = this.toUInt().floorDiv(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun floorDiv(other: ULong): ULong = this.toULong().floorDiv(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UByte): UByte = this.toUInt().mod(other.toUInt()).toUByte()
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UShort): UShort = this.toUInt().mod(other.toUInt()).toUShort()
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: UInt): UInt = this.toUInt().mod(other)
/** TODO */
@kotlin.internal.InlineOnly
public inline fun mod(other: ULong): ULong = this.toULong().mod(other)
/** Increments this value. */
@kotlin.internal.InlineOnly
public inline operator fun inc(): UShort = UShort(data.inc())