Files
swift-mirror/test/stdlib/FixedPointTruncation.swift
Anna Zaks b687c3ce9c Add runtime integer truncation checking to the conversion constructors
Add new builtins(by generalizing, renaming, and extending the builtins used for compile time integer literal checking). These new builtins truncate integers and check for overflow/truncation errors at runtime. Use these for FixedPoint conversion constructors.

Fix a routine in stdlib's String implementation and a test that relied on bitwise behavior of the constructors (and triggered overflows).

TODO:
- Teach CCP about these to get static checking.
- Add special builtins for same size signed <-> unsigned conversions.

Swift SVN r10432
2013-11-13 21:54:34 +00:00

31 lines
663 B
Swift

// RUN: %swift -i %s
// REQUIRES: swift_interpreter
// 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
UInt16(maxUInt16_u32)
UInt16(zero_u16)
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)