I Love Swift Programming Language en EasyStyle G.K.
12 de Jun de 2017•0 recomendaciones•1,845 vistas
1 de 59
Protocol-Oriented Integers #cswift
12 de Jun de 2017•0 recomendaciones•1,845 vistas
Descargar para leer sin conexión
Denunciar
Software
Swift 4 から導入される Protocol Oriented Integers の概要を整理してみた資料です。ここで紹介したもの以外にも詳細な機能があったりするので、それは不足するものの、プロトコル指向整数で何ができるのかを感じ取ってもらえる資料になってるかなって思います。2017/06/03 のカジュアル Swift 勉強会で発表しました。
35. // 任意の整数型からの全幅変換
init<T>(_ source: T) where T : BinaryInteger
// ビットパターンを使った内部表現そのままの変換
init<T>(extendingOrTruncating source: T) where T : BinaryInteger
// 強制的に範囲内に収める変換
init<T>(clamping source: T) where T : BinaryInteger
36. // 浮動小数点数型からの丸め変換(0 方向へ丸める)
init<T>(_ source: T) where T : FloatingPoint
// 浮動小数点数型からの Exact 変換(値を丸めない)
init?<T>(exactly source: T) where T : FloatingPoint
44. static func &>> <Other>(lhs: Self, rhs: Other) -> Self
where Other : BinaryInteger
static func &>>= <Other>(lhs: inout Self, rhs: Other)
where Other : BinaryInteger
static func &<< <Other>(lhs: Self, rhs: Other) -> Self
where Other : BinaryInteger
static func &<<= <Other>(lhs: inout Self, rhs: Other)
where Other : BinaryInteger
46. var words: [UInt] {
var result = [UInt]()
result.reserveCapacity(countRepresentedWords)
for i in 0 ..< countRepresentedWords {
result.append(_word(at: i))
}
return result
}
55. init(bigEndian value: Int)
init(littleEndian value: Int)
// 内部データを序列を加味して解釈する
var bigEndian: Int { get }
var littleEndian: Int { get }
// 内部データの序列を交換して解釈する
var byteSwapped: Int { get }