Home / Docs / Standard library / Built-in methods
to_int
Release v0.4.0Edition 0.2 and later
A built-in method, resolved by the type of its receiver (spec/14 §2). Edition 0.2 and later.
una
x.to_int() -> Int
where x: Int
x.to_int() -> Int
where x: F, one of I8, I16, I32, I64, U8, U16, U32, U64Converts x to Int, which every value of a fixed-width type fits, so it always succeeds (spec/18 §4). On a Text, to_int is the prelude function (spec/14 §1).
Receiver
Int: an integerxF, one of I8, I16, I32, I64, U8, U16, U32, U64: a fixed-width integerx, of one of the eight typesI8,I16,I32,I64,U8,U16,U32andU64
Returns
Int: the value of x as an Int, which every value of a fixed-width type fits, so it always succeeds.
See also
Example
src/shop.una
module shop
--- The largest `I64` total, widened to an `Int`, which has no largest value.
pub main() -> Unit
uses @console: Console[print]
=
let total: I64 = 9223372036854775807
let more = total.to_int() + 1
@console.print("{more}")una run . prints:
Output
9223372036854775808Specification
Generated from una v0.4.0 (docs/std/builtins.json, which is not part of the specification): built-in methods have no declaration, so una writes these signature lines and tests each against its checker. The specification governs: spec/14 §2.