2018-06-21 19:43:55 +01:00
|
|
|
const std = @import("std");
|
2019-02-08 23:18:47 +00:00
|
|
|
const expect = std.testing.expect;
|
2018-06-21 19:43:55 +01:00
|
|
|
const mem = std.mem;
|
2022-01-07 05:06:06 +00:00
|
|
|
const builtin = @import("builtin");
|
2018-06-21 19:43:55 +01:00
|
|
|
|
|
|
|
test "integer widening" {
|
|
|
|
var a: u8 = 250;
|
|
|
|
var b: u16 = a;
|
|
|
|
var c: u32 = b;
|
|
|
|
var d: u64 = c;
|
|
|
|
var e: u64 = d;
|
|
|
|
var f: u128 = e;
|
2021-05-04 19:23:22 +01:00
|
|
|
try expect(f == a);
|
2018-06-21 19:43:55 +01:00
|
|
|
}
|
2021-09-22 01:24:55 +01:00
|
|
|
|
|
|
|
test "implicit unsigned integer to signed integer" {
|
|
|
|
var a: u8 = 250;
|
|
|
|
var b: i16 = a;
|
|
|
|
try expect(b == 250);
|
|
|
|
}
|
2021-09-22 06:33:00 +01:00
|
|
|
|
|
|
|
test "float widening" {
|
|
|
|
var a: f16 = 12.34;
|
|
|
|
var b: f32 = a;
|
|
|
|
var c: f64 = b;
|
|
|
|
var d: f128 = c;
|
|
|
|
try expect(a == b);
|
|
|
|
try expect(b == c);
|
|
|
|
try expect(c == d);
|
|
|
|
}
|
|
|
|
|
|
|
|
test "float widening f16 to f128" {
|
|
|
|
// TODO https://github.com/ziglang/zig/issues/3282
|
2022-01-07 05:06:06 +00:00
|
|
|
if (builtin.cpu.arch == .aarch64) return error.SkipZigTest;
|
|
|
|
if (builtin.cpu.arch == .powerpc64le) return error.SkipZigTest;
|
2021-09-22 06:33:00 +01:00
|
|
|
|
|
|
|
var x: f16 = 12.34;
|
|
|
|
var y: f128 = x;
|
|
|
|
try expect(x == y);
|
|
|
|
}
|
|
|
|
|
|
|
|
test "cast small unsigned to larger signed" {
|
|
|
|
try expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
|
|
|
|
try expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));
|
|
|
|
}
|
|
|
|
fn castSmallUnsignedToLargerSigned1(x: u8) i16 {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
fn castSmallUnsignedToLargerSigned2(x: u16) i64 {
|
|
|
|
return x;
|
|
|
|
}
|