Protocol-Oriented Integers #cswift
-
Upload
tomohiro-kumagai -
Category
Software
-
view
910 -
download
0
Transcript of Protocol-Oriented Integers #cswift
Swift 3.0 and Later
http://ieeexplore.ieee.org/servlet/opac?punumber=4610933
Swift 4.0 and Later
init?<T>(exactly source: T) where T : BinaryInteger
associatedtype Magnitude : Comparable, ExpressibleByIntegerLiteral
var magnitude: Magnitude { get }
“-5.magnitude”
prefix static func +(x: Self) -> Self {
return x }
// 対象の型で、自身の型とその内部の絶対値表現の型とが同じだった場合 func abs<T>(_ x: T) -> T where T : SignedNumeric, T == T.Magnitude
// 対象の型が、比較可能な符号付き整数だった場合 func abs<T>(_ x: T) -> T where T : Comparable, T : SignedNumeric
// 任意の整数型からの全幅変換 init<T>(_ source: T) where T : BinaryInteger
// ビットパターンを使った内部表現そのままの変換 init<T>(extendingOrTruncating source: T) where T : BinaryInteger
// 強制的に範囲内に収める変換 init<T>(clamping source: T) where T : BinaryInteger
// 浮動小数点数型からの丸め変換(0 方向へ丸める) init<T>(_ source: T) where T : FloatingPoint
// 浮動小数点数型からの Exact 変換(値を丸めない) init?<T>(exactly source: T) where T : FloatingPoint
// 0 をインスタンス化するイニシャライザー init() {
self = 0 }
associatedtype Words
var words: Words { get }
// WORD 表現したときの WORD 数を取得 var countRepresentedWords: Int { get }
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
var words: [UInt] {
var result = [UInt]()
result.reserveCapacity(countRepresentedWords)
for i in 0 ..< countRepresentedWords {
result.append(_word(at: i)) }
return result }
init(bigEndian value: Int) init(littleEndian value: Int)
// 内部データを序列を加味して解釈する var bigEndian: Int { get } var littleEndian: Int { get }
// 内部データの序列を交換して解釈する var byteSwapped: Int { get }
// ビットパターンからの変換(nil の場合は 0 で初期化される様子) init(bitPattern pointer: OpaquePointer?)
// デコーダーからの変換(使用方法は未確認) init(from decoder: Decoder) throws
// エンコード機能もある様子(使用方法は未確認) func encode(to encoder: Encoder) throws
func multipliedFullWidth(by other: Int) -> (high: Int, low: Int.Magnitude)
func dividingFullWidth(_ dividend: (high: Int, low: Int.Magnitude)) -> (quotient: Int, remainder: Int)