MCPcopy Index your code
hub / github.com/sparkjsdev/spark / addOutputType

Function addOutputType

src/dyno/mathTypes.ts:351–386  ·  view source on GitHub ↗
(
  a: A,
  b: B,
  operation = "add",
)

Source from the content-addressed store, hash-verified

349// // Run-time type helper functions
350
351export function addOutputType<A extends AllValueTypes, B extends AllValueTypes>(
352 a: A,
353 b: B,
354 operation = "add",
355): AddOutput<A, B> {
356 const error = () => {
357 throw new Error(`Invalid ${operation} types: ${a}, ${b}`);
358 };
359 // @ts-ignore
360 if (a === b) return a as AddOutput<A, B>;
361 if (a === "int") {
362 if (isIntType(b)) return b as AddOutput<A, B>;
363 error();
364 }
365 if (b === "int") {
366 if (isIntType(a)) return a as AddOutput<A, B>;
367 error();
368 }
369 if (a === "uint") {
370 if (isUintType(b)) return b as AddOutput<A, B>;
371 error();
372 }
373 if (b === "uint") {
374 if (isUintType(a)) return a as AddOutput<A, B>;
375 error();
376 }
377 if (a === "float") {
378 if (isAllFloatType(b)) return b as AddOutput<A, B>;
379 error();
380 }
381 if (b === "float") {
382 if (isAllFloatType(a)) return a as AddOutput<A, B>;
383 error();
384 }
385 throw new Error(`Invalid ${operation} types: ${a}, ${b}`);
386}
387
388export function subOutputType<A extends AllValueTypes, B extends AllValueTypes>(
389 a: A,

Callers 2

subOutputTypeFunction · 0.85
divOutputTypeFunction · 0.85

Calls 4

isIntTypeFunction · 0.90
isUintTypeFunction · 0.90
isAllFloatTypeFunction · 0.90
errorFunction · 0.85

Tested by

no test coverage detected