@@ -68,6 +68,10 @@ abbrev Int.toInt8 := Int8.ofInt
68
68
abbrev Nat.toInt8 := Int8.ofNat
69
69
@[extern "lean_int8_to_int"]
70
70
def Int8.toInt (i : Int8) : Int := i.toBitVec.toInt
71
+ /--
72
+ This function has the same behavior as `Int.toNat` for negative numbers.
73
+ If you want to obtain the 2's complement representation use `toBitVec`.
74
+ -/
71
75
@[inline] def Int8.toNat (i : Int8) : Nat := i.toInt.toNat
72
76
@[extern "lean_int8_neg"]
73
77
def Int8.neg (i : Int8) : Int8 := ⟨⟨-i.toBitVec⟩⟩
@@ -161,6 +165,10 @@ abbrev Int.toInt16 := Int16.ofInt
161
165
abbrev Nat.toInt16 := Int16.ofNat
162
166
@[extern "lean_int16_to_int"]
163
167
def Int16.toInt (i : Int16) : Int := i.toBitVec.toInt
168
+ /--
169
+ This function has the same behavior as `Int.toNat` for negative numbers.
170
+ If you want to obtain the 2's complement representation use `toBitVec`.
171
+ -/
164
172
@[inline] def Int16.toNat (i : Int16) : Nat := i.toInt.toNat
165
173
@[extern "lean_int16_to_int8"]
166
174
def Int16.toInt8 (a : Int16) : Int8 := ⟨⟨a.toBitVec.signExtend 8 ⟩⟩
@@ -258,6 +266,10 @@ abbrev Int.toInt32 := Int32.ofInt
258
266
abbrev Nat.toInt32 := Int32.ofNat
259
267
@[extern "lean_int32_to_int"]
260
268
def Int32.toInt (i : Int32) : Int := i.toBitVec.toInt
269
+ /--
270
+ This function has the same behavior as `Int.toNat` for negative numbers.
271
+ If you want to obtain the 2's complement representation use `toBitVec`.
272
+ -/
261
273
@[inline] def Int32.toNat (i : Int32) : Nat := i.toInt.toNat
262
274
@[extern "lean_int32_to_int8"]
263
275
def Int32.toInt8 (a : Int32) : Int8 := ⟨⟨a.toBitVec.signExtend 8 ⟩⟩
@@ -359,6 +371,10 @@ abbrev Int.toInt64 := Int64.ofInt
359
371
abbrev Nat.toInt64 := Int64.ofNat
360
372
@[extern "lean_int64_to_int_sint"]
361
373
def Int64.toInt (i : Int64) : Int := i.toBitVec.toInt
374
+ /--
375
+ This function has the same behavior as `Int.toNat` for negative numbers.
376
+ If you want to obtain the 2's complement representation use `toBitVec`.
377
+ -/
362
378
@[inline] def Int64.toNat (i : Int64) : Nat := i.toInt.toNat
363
379
@[extern "lean_int64_to_int8"]
364
380
def Int64.toInt8 (a : Int64) : Int8 := ⟨⟨a.toBitVec.signExtend 8 ⟩⟩
0 commit comments