Revert adding generic V: Ordinal parameter to succ, pred, inc, dec (#22328)

* Use `int` in `digitsutils`, `dragonbox`, `schubfach`

* Fix error message
This commit is contained in:
konsumlamm
2023-08-05 18:38:46 +02:00
committed by GitHub
parent 873eaa3f65
commit e15e19308e
5 changed files with 17 additions and 17 deletions

View File

@@ -33,8 +33,8 @@ proc utoa2Digits*(buf: var openArray[char]; pos: int; digits: uint32) {.inline.}
buf[pos+1] = digits100[2 * digits + 1]
#copyMem(buf, unsafeAddr(digits100[2 * digits]), 2 * sizeof((char)))
proc trailingZeros2Digits*(digits: uint32): int32 {.inline.} =
return trailingZeros100[digits.int8]
proc trailingZeros2Digits*(digits: uint32): int {.inline.} =
trailingZeros100[digits]
when defined(js):
proc numToString(a: SomeInteger): cstring {.importjs: "((#) + \"\")".}

View File

@@ -1052,7 +1052,7 @@ when false:
proc memset(x: cstring; ch: char; L: int) {.importc, nodecl.}
proc memmove(a, b: cstring; L: int) {.importc, nodecl.}
proc utoa8DigitsSkipTrailingZeros*(buf: var openArray[char]; pos: int; digits: uint32): int32 {.inline.} =
proc utoa8DigitsSkipTrailingZeros*(buf: var openArray[char]; pos: int; digits: uint32): int {.inline.} =
dragonbox_Assert(digits >= 1)
dragonbox_Assert(digits <= 99999999'u32)
let q: uint32 = digits div 10000
@@ -1070,12 +1070,12 @@ proc utoa8DigitsSkipTrailingZeros*(buf: var openArray[char]; pos: int; digits: u
utoa2Digits(buf, pos + 6, rL)
return trailingZeros2Digits(if rL == 0: rH else: rL) + (if rL == 0: 2 else: 0)
proc printDecimalDigitsBackwards*(buf: var openArray[char]; pos: int; output64: uint64): int32 {.inline.} =
proc printDecimalDigitsBackwards*(buf: var openArray[char]; pos: int; output64: uint64): int {.inline.} =
var pos = pos
var output64 = output64
var tz: int32 = 0
var tz = 0
## number of trailing zeros removed.
var nd: int32 = 0
var nd = 0
## number of decimal digits processed.
## At most 17 digits remaining
if output64 >= 100000000'u64:
@@ -1220,7 +1220,7 @@ proc formatDigits*[T: Ordinal](buffer: var openArray[char]; pos: T; digits: uint
## dE+123 or d.igitsE+123
decimalDigitsPosition = 1
var digitsEnd = pos + int(decimalDigitsPosition + numDigits)
let tz: int32 = printDecimalDigitsBackwards(buffer, digitsEnd, digits)
let tz = printDecimalDigitsBackwards(buffer, digitsEnd, digits)
dec(digitsEnd, tz)
dec(numDigits, tz)
## decimal_exponent += tz; // => decimal_point unchanged.

View File

@@ -244,12 +244,12 @@ proc toDecimal32(ieeeSignificand: uint32; ieeeExponent: uint32): FloatingDecimal
## ToChars
## ==================================================================================================
proc printDecimalDigitsBackwards[T: Ordinal](buf: var openArray[char]; pos: T; output: uint32): int32 {.inline.} =
proc printDecimalDigitsBackwards[T: Ordinal](buf: var openArray[char]; pos: T; output: uint32): int {.inline.} =
var output = output
var pos = pos
var tz: int32 = 0
var tz = 0
## number of trailing zeros removed.
var nd: int32 = 0
var nd = 0
## number of decimal digits processed.
## At most 9 digits remaining
if output >= 10000:
@@ -355,7 +355,7 @@ proc formatDigits[T: Ordinal](buffer: var openArray[char]; pos: T; digits: uint3
## dE+123 or d.igitsE+123
decimalDigitsPosition = 1
var digitsEnd = pos + decimalDigitsPosition + numDigits
let tz: int32 = printDecimalDigitsBackwards(buffer, digitsEnd, digits)
let tz = printDecimalDigitsBackwards(buffer, digitsEnd, digits)
dec(digitsEnd, tz)
dec(numDigits, tz)
## decimal_exponent += tz; // => decimal_point unchanged.

View File

@@ -1,4 +1,4 @@
proc succ*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Succ", noSideEffect.} =
proc succ*[T: Ordinal](x: T, y: int = 1): T {.magic: "Succ", noSideEffect.} =
## Returns the `y`-th successor (default: 1) of the value `x`.
##
## If such a value does not exist, `OverflowDefect` is raised
@@ -7,7 +7,7 @@ proc succ*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Succ", noSideEffect.} =
assert succ(5) == 6
assert succ(5, 3) == 8
proc pred*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Pred", noSideEffect.} =
proc pred*[T: Ordinal](x: T, y: int = 1): T {.magic: "Pred", noSideEffect.} =
## Returns the `y`-th predecessor (default: 1) of the value `x`.
##
## If such a value does not exist, `OverflowDefect` is raised
@@ -16,7 +16,7 @@ proc pred*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Pred", noSideEffect.} =
assert pred(5) == 4
assert pred(5, 3) == 2
proc inc*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Inc", noSideEffect.} =
proc inc*[T: Ordinal](x: var T, y: int = 1) {.magic: "Inc", noSideEffect.} =
## Increments the ordinal `x` by `y`.
##
## If such a value does not exist, `OverflowDefect` is raised or a compile
@@ -28,7 +28,7 @@ proc inc*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Inc", noSideEffect.} =
inc(i, 3)
assert i == 6
proc dec*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Dec", noSideEffect.} =
proc dec*[T: Ordinal](x: var T, y: int = 1) {.magic: "Dec", noSideEffect.} =
## Decrements the ordinal `x` by `y`.
##
## If such a value does not exist, `OverflowDefect` is raised or a compile
@@ -93,7 +93,7 @@ proc `*`*(x, y: int16): int16 {.magic: "MulI", noSideEffect.}
proc `*`*(x, y: int32): int32 {.magic: "MulI", noSideEffect.}
proc `*`*(x, y: int64): int64 {.magic: "MulI", noSideEffect.}
proc `div`*(x, y: int): int {.magic: "DivI", noSideEffect.} =
proc `div`*(x, y: int): int {.magic: "DivI", noSideEffect.} =
## Computes the integer division.
##
## This is roughly the same as `math.trunc(x/y).int`.

View File

@@ -2,7 +2,7 @@ discard """
errormsg: "type mismatch: got <int>"
nimout: '''tprevent_forloopvar_mutations.nim(16, 3) Error: type mismatch: got <int>
but expected one of:
proc inc[T, V: Ordinal](x: var T; y: V = 1)
proc inc[T: Ordinal](x: var T; y: int = 1)
first type mismatch at position: 1
required type for x: var T: Ordinal
but expression 'i' is immutable, not 'var'