Contents

ivarflakstad/bfloat16.swift

Brain floating point type for Swift.

Usage

Import BFloat16:

import BFloat16

After 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.782

Also 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)

License

BFloat16 is available under the MIT license. See the LICENSE file for more info.

Package Metadata

Repository: ivarflakstad/bfloat16.swift

Default branch: main

README: README.md