program main
  fn narrow(value: f64) -> (result i64 i32)
    call std.num.f64_to_i64_result
      var value
  fn zero_ok() -> (result i64 i32)
    call narrow
      binary -
        float 2.5
        float 2.5
  fn negative_ok() -> (result i64 i32)
    call narrow
      binary -
        float 1
        float 13
  fn fractional_err() -> (result i64 i32)
    call narrow
      binary /
        float 7
        float 2
  fn above_high_err() -> (result i64 i32)
    call narrow
      float 9223372036854776000
  fn main() -> i32
    local let value: (result i64 i32)
      call negative_ok
    if
      std.result.is_ok
        var value
      if
        binary =
          std.result.unwrap_ok
            var value
          i64 -12
        int 0
        int 1
      std.result.unwrap_err
        var value
  test "f64 zero narrows to i64"
    local let value: (result i64 i32)
      call zero_ok
    if
      std.result.is_ok
        var value
      binary =
        std.result.unwrap_ok
          var value
        i64 0
      bool false
  test "negative f64 narrows to i64"
    local let value: (result i64 i32)
      call negative_ok
    if
      std.result.is_ok
        var value
      binary =
        std.result.unwrap_ok
          var value
        i64 -12
      bool false
  test "fractional f64 returns err for i64"
    local let value: (result i64 i32)
      call fractional_err
    if
      std.result.is_err
        var value
      binary =
        std.result.unwrap_err
          var value
        int 1
      bool false
  test "above i64 range f64 returns err"
    local let value: (result i64 i32)
      call above_high_err
    if
      std.result.is_err
        var value
      binary =
        std.result.unwrap_err
          var value
        int 1
      bool false
