forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFixedPointTruncation.swift
51 lines (45 loc) · 1.02 KB
/
FixedPointTruncation.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// Unsigned to signed truncation.
var maxInt8_u16: UInt16 = 127
Int8(maxInt8_u16)
var maxInt8_u64: UInt64 = 127
Int8(maxInt8_u64)
var zero_u16: UInt16 = 0
Int8(zero_u16)
// Unsigned to unsigned truncation.
var maxUInt16_u32: UInt32 = 0xFFFF
var small_u32: UInt32 = 0xF
var zero_u32: UInt32 = 0
UInt16(maxUInt16_u32)
UInt16(zero_u32)
UInt16(small_u32)
// Signed to unsigned truncation.
var maxUInt16_i64: Int64 = 0xFFFF
UInt16(maxUInt16_i64)
var small_u16: Int16 = 0xF
UInt8(small_u16)
// Signed to signed truncation.
var minInt8_i64: Int64 = -128
Int8(minInt8_i64)
Int16(minInt8_i64)
var zero_i64: Int64 = 0
Int8(zero_i64)
// Same size conversions.
var sssmall_i8: Int8 = 2
UInt8(sssmall_i8)
var sssmall_u8: UInt8 = 2
Int(sssmall_u8)
var szero_i8: Int8 = 0
UInt8(szero_i8)
var szero_u8: UInt8 = 0
Int(szero_u8)
var smax_i8: Int8 = 127
UInt8(smax_i8)
var smax_u8: UInt8 = 127
Int(smax_u8)
// Ext conversions.
UInt16(sssmall_i8)
UInt16(szero_i8)
UInt32(sssmall_u8)
UInt32(szero_u8)