(module main)

(import std.num (i32_to_i64 i32_to_f64 i64_to_f64 i64_to_i32_result f64_to_i32_result f64_to_i64_result i32_to_string u32_to_string i64_to_string u64_to_string f64_to_string i64_to_i32_or f64_to_i32_or f64_to_i64_or))

(fn imported_num_widening_ok () -> bool
  (if (= (i32_to_i64 42) 42i64)
    (if (= (i32_to_f64 42) 42.0)
      (= (i64_to_f64 42i64) 42.0)
      false)
    false))

(fn imported_num_checked_ok () -> bool
  (if (= (unwrap_ok (i64_to_i32_result 42i64)) 42)
    (if (= (unwrap_ok (f64_to_i32_result 42.0)) 42)
      (= (unwrap_ok (f64_to_i64_result 42.0)) 42i64)
      false)
    false))

(fn imported_num_strings_ok () -> bool
  (if (= (i32_to_string 42) "42")
    (if (= (u32_to_string 42u32) "42")
      (if (= (i64_to_string 42i64) "42")
        (if (= (u64_to_string 42u64) "42")
          (= (f64_to_string 42.0) "42.0")
          false)
        false)
      false)
    false))

(fn imported_num_fallbacks_ok () -> bool
  (if (= (i64_to_i32_or 42i64 7) 42)
    (if (= (i64_to_i32_or 2147483648i64 7) 7)
      (if (= (f64_to_i32_or 42.0 7) 42)
        (if (= (f64_to_i32_or 2147483648.0 7) 7)
          (if (= (f64_to_i64_or 42.0 7i64) 42i64)
            (= (f64_to_i64_or 100000000000000000000.0 7i64) 7i64)
            false)
          false)
        false)
      false)
    false))

(fn imported_num_helpers_ok () -> bool
  (if (imported_num_widening_ok)
    (if (imported_num_checked_ok)
      (if (imported_num_strings_ok)
        (imported_num_fallbacks_ok)
        false)
      false)
    false))

(fn main () -> i32
  (if (imported_num_helpers_ok)
    42
    1))

(test "explicit std num widening"
  (imported_num_widening_ok))

(test "explicit std num checked conversions"
  (imported_num_checked_ok))

(test "explicit std num to string"
  (imported_num_strings_ok))

(test "explicit std num checked fallbacks"
  (imported_num_fallbacks_ok))

(test "explicit std num helpers all"
  (= (main) 42))
