MCPcopy Index your code
hub / github.com/culvertsoft/mgen / checkInt

Function checkInt

mgen-javascriptlib/src/main/javascript/mgen-lib.js:473–497  ·  view source on GitHub ↗
(value, size, type, options)

Source from the content-addressed store, hash-verified

471 }
472
473 function checkInt(value, size, type, options) {
474 if (size > 32) {
475 if (options.warn) {
476 window.console.warn("mGen cannot handle 64 bit integers well due to javascript limitations. See https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/js-ctypes_reference/Int64");
477 }
478 }
479
480 if (typeof value === "undefined" || value === null) {
481 return;
482 }
483
484 if (typeof value !== "number") {
485 throw Error("Tried to create " + type + " but data was of type: " + (typeof value));
486 }
487
488 if (isNumeric(parseInt(value, 10)) && (parseFloat(value, 10) === parseInt(value, 10))) {
489 var lim = Math.pow(2, size - 1);
490 if (value > lim - 1 || value < -lim) {
491 throw Error(value + " is out of range for int" + size);
492 }
493 return true;
494 } else {
495 throw Error("Tried to create " + type + " but data ( " + value + " ) was not a valid integer.");
496 }
497 }
498
499 function checkFloat(value, size, type) {
500 if (typeof value === "undefined" || value === null) {

Callers 1

createFieldOfTypeFunction · 0.85

Calls 1

isNumericFunction · 0.85

Tested by

no test coverage detected