MCPcopy Create free account
hub / github.com/DFin/Neural-Network-Visualisation / float16ToFloat32

Function float16ToFloat32

assets/main.js:705–724  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

703}
704
705function float16ToFloat32(value) {
706 const sign = (value & 0x8000) >> 15;
707 const exponent = (value & 0x7c00) >> 10;
708 const fraction = value & 0x03ff;
709
710 let result;
711 if (exponent === 0) {
712 if (fraction === 0) {
713 result = 0;
714 } else {
715 result = (fraction / 0x400) * Math.pow(2, -14);
716 }
717 } else if (exponent === 0x1f) {
718 result = fraction === 0 ? Number.POSITIVE_INFINITY : Number.NaN;
719 } else {
720 result = (1 + fraction / 0x400) * Math.pow(2, exponent - 15);
721 }
722
723 return sign === 1 ? -result : result;
724}
725
726function decodeFloat16Base64(base64, expectedLength) {
727 const bytes = decodeBase64ToUint8Array(base64);

Callers 1

decodeFloat16Base64Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected