UNPKG

gnablib

Version:

A lean, zero dependency library to provide a useful base for your project.

2 lines 373 B
/*! Copyright 2023-2024 the gnablib contributors MPL-1.1 */ import{sNum as t}from"../safe/safe.js";import{fpb32 as o}from"./ieee754-fpb.js";export const bfloat16={toBytes:function(t){return o.toBytes(t).subarray(0,2)},fromBytes:function(r,e=0){t("pos",e).unsigned().atMost(r.length-2).throwNot();const s=new Uint8Array(4);return s.set(r.subarray(e,e+2)),o.fromBytes(s,0)}};