zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

test_integer_widening.zig (587B) - Raw


      1 const std = @import("std");
      2 const builtin = @import("builtin");
      3 const expect = std.testing.expect;
      4 const mem = std.mem;
      5 
      6 test "integer widening" {
      7     const a: u8 = 250;
      8     const b: u16 = a;
      9     const c: u32 = b;
     10     const d: u64 = c;
     11     const e: u64 = d;
     12     const f: u128 = e;
     13     try expect(f == a);
     14 }
     15 
     16 test "implicit unsigned integer to signed integer" {
     17     const a: u8 = 250;
     18     const b: i16 = a;
     19     try expect(b == 250);
     20 }
     21 
     22 test "float widening" {
     23     const a: f16 = 12.34;
     24     const b: f32 = a;
     25     const c: f64 = b;
     26     const d: f128 = c;
     27     try expect(d == a);
     28 }
     29 
     30 // test