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, U64

Converts 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

Returns

Int: the value of x as an Int, which every value of a fixed-width type fits, so it always succeeds.

See also

to_int, to_i64

Example

src/shop.unauna
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
9223372036854775808

Specification

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.