gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 2 kB
JavaScript
/*! Copyright 2023-2024 the gnablib contributors MPL-1.1 */
import{fpb32 as n,fpb64 as e}from"../../codec/ieee754-fpb.js";import{FromBinResult as t}from"../../primitive/FromBinResult.js";import{ColType as o}from"./ColType.js";import{ACudColType as r}from"./ACudColType.js";import{TypeProblem as l}from"../../error/probs/TypeProblem.js";import{ContentError as i}from"../../error/ContentError.js";class s extends r{constructor(n=!1){super(n)}valid(n){if(null==n&&!this.nullable)return l.Null("Float")}_binUnknown(n,e,o){if(e+1>n.length)return new t(0,void 0,"Float.binUnknown unable to find length");const r=n[e++];if(0===r)return this.nullable?new t(1,void 0):new t(0,void 0,"Float.binUnknown cannot be null");if(r!==o)return new t(0,void 0,`Float8.binUnknown invalid length (${o} got ${r})`);const l=e+r;return l>n.length?new t(0,void 0,"Float.binUnknown missing data"):new t(9,n.slice(e,l))}}export class Float4 extends s{constructor(){super(...arguments),this.mysqlType="FLOAT",this.sqliteType="FLOAT",this.postgresType="real",this.cudType="float4",this._colType=o.Float4}cudByteSize(){return 4}unknownBin(e){if(null==e&&!this.nullable)throw new i("cannot be null","Float",void 0);if("number"!=typeof e)throw new TypeError("Float required");const t=n.toBytes(e),o=new Uint8Array(t.length+1);return o[0]=t.length,o.set(t,1),o}binUnknown(e,o){const r=this._binUnknown(e,o,4);return null==r.value?r.switchT():new t(5,n.fromBytes(r.value))}}export class Float8 extends s{constructor(){super(...arguments),this.mysqlType="DOUBLE",this.sqliteType="DOUBLE",this.postgresType="double precision",this.cudType="float8",this._colType=o.Float8}cudByteSize(){return 8}unknownBin(n){if(null==n&&!this.nullable)throw new i("cannot be null","Float",void 0);if("number"!=typeof n)throw new TypeError("Float required");const t=e.toBytes(n),o=new Uint8Array(t.length+1);return o[0]=t.length,o.set(t,1),o}binUnknown(n,o){const r=this._binUnknown(n,o,8);return null==r.value?r.switchT():new t(9,e.fromBytes(r.value))}}