Skip to content

Instantly share code, notes, and snippets.

Rainer Brockerhoff rbrockerhoff

Block or report user

Report or block rbrockerhoff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rbrockerhoff
rbrockerhoff / Decimal.md
Created Mar 18, 2016
Pre-proposal: Safer Decimal Calculations
View Decimal.md

Pre-proposal: Safer Decimal Calculations

Quoting the “The Swift Programming Language” book: “Swift adopts safe programming patterns…”; “Swift is friendly to new programmers”. The words “safe” and “safety” are found many times in the book and in online documentation. The usual rationale for safe features is, to quote a typical sentence, “…enables you to catch and fix errors as early as possible in the development process”.

One frequent stumbling point for both new and experienced programmers stems from the vagaries of binary floating-point arithmetic. This tentative pre-proposal suggests one possible way to make the dangers somewhat more clear.

@rbrockerhoff
rbrockerhoff / bug.swift
Last active Aug 29, 2015
Must be a Swift bug
View bug.swift
extension Dictionary {
mutating func merge <S: Sequence where S.GeneratorType.Element == Element> (seq: S) {
var gen = seq.generate()
while let (key: KeyType, value: ValueType) = gen.next() {
self[key] = value
}
}
}
var dict = [0:0]
@rbrockerhoff
rbrockerhoff / dictext.swift
Last active Dec 24, 2015
Some useful extensions to Dictionary
View dictext.swift
extension Dictionary {
init (_ array: Array<Element>) {
self = [ : ]
self.merge(array)
}
mutating func merge (array: Array<Element>) {
for (key: KeyType, value: ValueType) in array {
self[key] = value
}
You can’t perform that action at this time.