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

Method cmp

lib.esm/utils/fixednumber.js:338–356  ·  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

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

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