Brain floating point type for Swift.
Inspired by floating point implementations in
To install via the Swift Package Manager add the following line to your Package.swift file's dependencies:
.package(url: "https://github.com/ivarflakstad/BFloat16.swift.git", from: "1.0.0")Import BFloat16:
import BFloat16After importing, use the imported BFloat16 type exactly like you'd use Swift's builtin Float, Double, or Float80 types.
func printDouble(value: BFloat16) {
print(value * 2.0)
}
printDouble(7.891)
> 15.782Also supports SIMD
var actual = SIMD4<BFloat16>(1.0, 2.0, 3.0, 4.0)
for _ in 0...10 {
actual += actual
}
let expected = SIMD4<BFloat16>(2048.0, 4096.0, 6144.0, 8192.0)
assert(actual == expected)BFloat16 is available under the MIT license. See the LICENSE file for more info.