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

Method cmp

lib.commonjs/utils/fixednumber.js:341–359  ·  view source on GitHub ↗

* Returns a comparison result between %%this%% and %%other%%. * * This is suitable for use in sorting, where ``-1`` implies %%this%% * is smaller, ``1`` implies %%this%% is larger and ``0`` implies * both are equal.

(other)

Source from the content-addressed store, hash-verified

339 * both are equal.
340 */
341 cmp(other) {
342 let a = this.value, b = other.value;
343 // Coerce a and b to the same magnitude
344 const delta = this.decimals - other.decimals;
345 if (delta > 0) {
346 b *= getTens(delta);
347 }
348 else if (delta < 0) {
349 a *= getTens(-delta);
350 }
351 // Comnpare
352 if (a < b) {
353 return -1;
354 }
355 if (a > b) {
356 return 1;
357 }
358 return 0;
359 }
360 /**
361 * Returns true if %%other%% is equal to %%this%%.
362 */

Callers 5

eqMethod · 0.95
ltMethod · 0.95
lteMethod · 0.95
gtMethod · 0.95
gteMethod · 0.95

Calls 1

getTensFunction · 0.70

Tested by

no test coverage detected