MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / checkValue

Function checkValue

lib.commonjs/utils/fixednumber.js:36–58  ·  view source on GitHub ↗
(val, format, safeOp)

Source from the content-addressed store, hash-verified

34 return BigInt("1" + result.substring(0, decimals));
35}
36function checkValue(val, format, safeOp) {
37 const width = BigInt(format.width);
38 if (format.signed) {
39 const limit = (BN_1 << (width - BN_1));
40 (0, errors_js_1.assert)(safeOp == null || (val >= -limit && val < limit), "overflow", "NUMERIC_FAULT", {
41 operation: safeOp, fault: "overflow", value: val
42 });
43 if (val > BN_0) {
44 val = (0, maths_js_1.fromTwos)((0, maths_js_1.mask)(val, width), width);
45 }
46 else {
47 val = -(0, maths_js_1.fromTwos)((0, maths_js_1.mask)(-val, width), width);
48 }
49 }
50 else {
51 const limit = (BN_1 << width);
52 (0, errors_js_1.assert)(safeOp == null || (val >= 0 && val < limit), "overflow", "NUMERIC_FAULT", {
53 operation: safeOp, fault: "overflow", value: val
54 });
55 val = (((val % limit) + limit) % limit) & (limit - BN_1);
56 }
57 return val;
58}
59function getFormat(value) {
60 if (typeof (value) === "number") {
61 value = `fixed128x${value}`;

Callers 5

#checkValueMethod · 0.70
roundMethod · 0.70
fromValueMethod · 0.70
fromStringMethod · 0.70
fromBytesMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected