tiny.simd.BFloat16
Defined in bfloat.
API (12)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/simd/src/bfloat.zig:4
zig
pub const BFloat16 = extern struct { pub const is_bfloat16 = true; pub const Storage = u16; bits: u16, pub fn fromBits(bits: u16) BFloat16 { return .{ .bits = bits }; } pub fn fromF32(value: f32) BFloat16 { return .{ .bits = bitsFromF32(value) }; } pub fn fromF64(value: f64) BFloat16 { const bits: u64 = @bitCast(value); const rounded_bits = (bits & 0xffff_ffc0_0000_0000) | ((bits +% 0x0000_003f_ffff_ffff) & 0x0000_0040_0000_0000); return fromF32(@floatCast(@as(f64, @bitCast(rounded_bits)))); } pub fn toF32(self: BFloat16) f32 { return f32FromBits(self.bits); } pub fn neg(self: BFloat16) BFloat16 { return fromBits(self.bits ^ 0x8000); } pub fn add(self: BFloat16, other: BFloat16) BFloat16 { return fromF32(self.toF32() + other.toF32()); } pub fn sub(self: BFloat16, other: BFloat16) BFloat16 { return fromF32(self.toF32() - other.toF32()); } pub fn mul(self: BFloat16, other: BFloat16) BFloat16 { return fromF32(self.toF32() * other.toF32()); } pub fn div(self: BFloat16, other: BFloat16) BFloat16 { return fromF32(self.toF32() / other.toF32()); }};Source: lib/simd/src/root.zig:143
zig
pub const BFloat16 = bfloat.BFloat16;Audit
| Definitions | 9 |
|---|---|
| Public names | 18 |
| Members | 1 |
| Version | 26.7.0 |
| Revision | daab053ee433 |