🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

safe-mts

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

safe-mts - npm Package Compare versions

Comparing version
0.1.1
to
0.2.1
+2
lib/utils/decimal-count.d.ts
export declare function decimalCount(val: number): number;
export declare function issScientific(val: number): boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.issScientific = exports.decimalCount = void 0;
const parse_scientific_1 = require("./parse-scientific");
function decimalCount(val) {
if (Math.floor(val) === val)
return 0;
if (!issScientific(val))
return val.toString().split(".")[1].length || 0;
return (0, parse_scientific_1.parseScientific)(val.toString()).split(".")[1].length || 0;
}
exports.decimalCount = decimalCount;
function issScientific(val) {
return val.toString().includes("e");
}
exports.issScientific = issScientific;
//# sourceMappingURL=decimal-count.js.map
{"version":3,"file":"decimal-count.js","sourceRoot":"","sources":["../../src/utils/decimal-count.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAErD,SAAgB,YAAY,CAAC,GAAW;IACtC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG;QAAE,OAAO,CAAC,CAAC;IAEtC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC;IAEzE,OAAO,IAAA,kCAAe,EAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC;AACnE,CAAC;AAND,oCAMC;AAED,SAAgB,aAAa,CAAC,GAAW;IACvC,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AAFD,sCAEC"}
export declare function parseScientific(num: string): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseScientific = void 0;
function parseScientific(num) {
if (!/\d+\.?\d*e[+-]*\d+/i.test(num))
return num;
const numberSign = Math.sign(Number(num));
num = Math.abs(Number(num)).toString();
const [coefficient, exponent] = num.toLowerCase().split("e");
let zeros = Math.abs(Number(exponent));
const exponentSign = Math.sign(Number(exponent));
const [integer, decimals] = (coefficient.indexOf(".") != -1 ? coefficient : `${coefficient}.`).split(".");
if (exponentSign === -1) {
zeros -= integer.length;
num =
zeros < 0
? integer.slice(0, zeros) + "." + integer.slice(zeros) + decimals
: "0." + "0".repeat(zeros) + integer + decimals;
}
else {
if (decimals)
zeros -= decimals.length;
num =
zeros < 0
? integer + decimals.slice(0, zeros) + "." + decimals.slice(zeros)
: integer + decimals + "0".repeat(zeros);
}
return numberSign < 0 ? "-" + num : num;
}
exports.parseScientific = parseScientific;
//# sourceMappingURL=parse-scientific.js.map
{"version":3,"file":"parse-scientific.js","sourceRoot":"","sources":["../../src/utils/parse-scientific.ts"],"names":[],"mappings":";;;AAAA,SAAgB,eAAe,CAAC,GAAW;IAEzC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IAGjD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAGvC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7D,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjD,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,CAC1B,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,CACjE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEb,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE;QACvB,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;QACxB,GAAG;YACD,KAAK,GAAG,CAAC;gBACP,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,QAAQ;gBACjE,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,GAAG,QAAQ,CAAC;KACrD;SAAM;QACL,IAAI,QAAQ;YAAE,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC;QACvC,GAAG;YACD,KAAK,GAAG,CAAC;gBACP,CAAC,CAAC,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC;gBAClE,CAAC,CAAC,OAAO,GAAG,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KAC9C;IAED,OAAO,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAC1C,CAAC;AA/BD,0CA+BC"}
export declare function safeAdd(a: number, b: number): number;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.safeAdd = void 0;
const decimal_count_1 = require("./decimal-count");
function safeAdd(a, b) {
const aMultiplier = Math.pow(10, (0, decimal_count_1.decimalCount)(a));
const bMultiplier = Math.pow(10, (0, decimal_count_1.decimalCount)(b));
let multiplier = Math.max(aMultiplier, bMultiplier);
const aInt = parseInt(String(a * multiplier));
const bInt = parseInt(String(b * multiplier));
return (aInt + bInt) / multiplier;
}
exports.safeAdd = safeAdd;
//# sourceMappingURL=safe-add.js.map
{"version":3,"file":"safe-add.js","sourceRoot":"","sources":["../../src/utils/safe-add.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAE/C,SAAgB,OAAO,CAAC,CAAS,EAAE,CAAS;IAC1C,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAA,4BAAY,EAAC,CAAC,CAAC,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAA,4BAAY,EAAC,CAAC,CAAC,CAAC,CAAC;IAElD,IAAI,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAEpD,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAE9C,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,UAAU,CAAC;AACpC,CAAC;AAVD,0BAUC"}
export declare function safeMultiply(a: number, b: number): number;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.safeMultiply = void 0;
const decimal_count_1 = require("./decimal-count");
function safeMultiply(a, b) {
const aMultiplier = Math.pow(10, (0, decimal_count_1.decimalCount)(a));
const bMultiplier = Math.pow(10, (0, decimal_count_1.decimalCount)(b));
const aInt = parseInt(String(a * aMultiplier));
const bInt = parseInt(String(b * bMultiplier));
const reducer = aMultiplier * bMultiplier;
return (aInt * bInt) / reducer;
}
exports.safeMultiply = safeMultiply;
//# sourceMappingURL=safe-multiply.js.map
{"version":3,"file":"safe-multiply.js","sourceRoot":"","sources":["../../src/utils/safe-multiply.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAE/C,SAAgB,YAAY,CAAC,CAAS,EAAE,CAAS;IAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAA,4BAAY,EAAC,CAAC,CAAC,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAA,4BAAY,EAAC,CAAC,CAAC,CAAC,CAAC;IAElD,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;IAE/C,MAAM,OAAO,GAAG,WAAW,GAAG,WAAW,CAAC;IAE1C,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC;AACjC,CAAC;AAVD,oCAUC"}
export declare function safeSubtract(a: number, b: number): number;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.safeSubtract = void 0;
const decimal_count_1 = require("./decimal-count");
function safeSubtract(a, b) {
const aMultiplier = Math.pow(10, (0, decimal_count_1.decimalCount)(a));
const bMultiplier = Math.pow(10, (0, decimal_count_1.decimalCount)(b));
let multiplier = Math.max(aMultiplier, bMultiplier);
const aInt = parseInt(String(a * multiplier));
const bInt = parseInt(String(b * multiplier));
return (aInt - bInt) / multiplier;
}
exports.safeSubtract = safeSubtract;
//# sourceMappingURL=safe-subtract.js.map
{"version":3,"file":"safe-subtract.js","sourceRoot":"","sources":["../../src/utils/safe-subtract.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAE/C,SAAgB,YAAY,CAAC,CAAS,EAAE,CAAS;IAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAA,4BAAY,EAAC,CAAC,CAAC,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAA,4BAAY,EAAC,CAAC,CAAC,CAAC,CAAC;IAElD,IAAI,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAEpD,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAE9C,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,UAAU,CAAC;AACpC,CAAC;AAVD,oCAUC"}
+5
-4

@@ -1,4 +0,5 @@

export * from "./decimal-count";
export * from "./safe-add";
export * from "./safe-subtract";
export * from "./safe-multiply";
export * from "./utils/parse-scientific";
export * from "./utils/decimal-count";
export * from "./utils/safe-add";
export * from "./utils/safe-subtract";
export * from "./utils/safe-multiply";

@@ -17,6 +17,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./decimal-count"), exports);
__exportStar(require("./safe-add"), exports);
__exportStar(require("./safe-subtract"), exports);
__exportStar(require("./safe-multiply"), exports);
__exportStar(require("./utils/parse-scientific"), exports);
__exportStar(require("./utils/decimal-count"), exports);
__exportStar(require("./utils/safe-add"), exports);
__exportStar(require("./utils/safe-subtract"), exports);
__exportStar(require("./utils/safe-multiply"), exports);
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,6CAA2B;AAC3B,kDAAgC;AAChC,kDAAgC"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,wDAAsC;AACtC,mDAAiC;AACjC,wDAAsC;AACtC,wDAAsC"}
{
"name": "safe-mts",
"version": "0.1.1",
"version": "0.2.1",
"description": "Safe arithmetics around floating point numbers",

@@ -11,4 +11,12 @@ "main": "lib/index",

"license": "MIT",
"files": ["lib"],
"keywords": ["safe-mts","safe-maths","safemaths", "floating point", "arithmetic"],
"files": [
"lib"
],
"keywords": [
"safe-mts",
"safe-maths",
"safemaths",
"floating point",
"arithmetic"
],
"bugs": {

@@ -15,0 +23,0 @@ "url": "https://github.com/Xavier577/safe-maths/issues"