Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smath

Package Overview
Dependencies
Maintainers
0
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smath - npm Package Compare versions

Comparing version 1.10.0 to 1.11.0

35

dist/bin.js
#!/usr/bin/env node
"use strict";
var _a, _b;
var _a, _b, _c, _d;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -22,8 +22,8 @@ var _1 = require(".");

console.log(' clamp <n> <min> <max> : Clamp `n` between `min` and `max`');
console.log(' normalize <n> <min> <max>: Normalize `n` between `min` and `max`');
console.log(' expand <n> <min> <max> : Expand normalized `n` between `min` and `max`');
console.log(' translate <n> <min1> <max1> <min2> <max2>');
console.log(' : Linearly interpolate `n` from `min1`, `max1` to `min2`, `max2`');
console.log(' linspace <min> <max> <n> : Generate `n` linearly spaced numbers between `min` and `max`');
console.log(' logspace <min> <max> <n> : Generate `n` logarithmically spaced numbers between `min` and `max`');
console.log(' normalize <n> <min> <max>: Normalize `n` between `min` and `max`');
console.log(' translate <n> <min1> <max1> <min2> <max2>');
console.log(' : Linearly interpolate `n` from `min1`, `max1` to `min2`, `max2`');
console.log(' factorial <n> : Compute `n!` (factorial)');

@@ -44,3 +44,4 @@ console.log(' factors <n> : List the prime factors of `n`');

console.log(' rdist <n> [mean] [stdev] : Generate `n` normally-distributed random floats');
console.log(' rseq <min> <max> : Randomize a sequence of integers from `min` to `max`');
console.log(' rat <n> [eps] : Decompose `n` into a ratio');
console.log(' mixed <n> [eps] : Decompose `n` into a mixed number');
process.exit(1);

@@ -57,2 +58,6 @@ }

}
case ('normalize'): {
console.log(_1.SMath.normalize(nums[0], nums[1], nums[2]));
break;
}
case ('expand'): {

@@ -62,2 +67,6 @@ console.log(_1.SMath.expand(nums[0], nums[1], nums[2]));

}
case ('translate'): {
console.log(_1.SMath.translate(nums[0], nums[1], nums[2], nums[3], nums[4]));
break;
}
case ('linspace'): {

@@ -71,10 +80,2 @@ console.log(_1.SMath.linspace(nums[0], nums[1], nums[2]));

}
case ('normalize'): {
console.log(_1.SMath.normalize(nums[0], nums[1], nums[2]));
break;
}
case ('translate'): {
console.log(_1.SMath.translate(nums[0], nums[1], nums[2], nums[3], nums[4]));
break;
}
case ('factorial'): {

@@ -140,6 +141,10 @@ console.log(_1.SMath.factorial(nums[0]));

}
case ('rseq'): {
console.log(_1.SMath.rseq(nums[0], nums[1]));
case ('rat'): {
console.log(_1.SMath.rat(nums[0], (_c = nums[1]) !== null && _c !== void 0 ? _c : 1e-6));
break;
}
case ('mixed'): {
console.log(_1.SMath.mixed(nums[0], (_d = nums[1]) !== null && _d !== void 0 ? _d : 1e-6));
break;
}
case (''): {

@@ -146,0 +151,0 @@ console.error('Missing argument. Use with "help" for a list of commands.');

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -401,24 +412,2 @@ exports.SMath = void 0;

/**
* Randomize a sequence of integers from `min` to `max`.
* @param min The minimum integer in the randomized sequence
* @param max The maximum integer in the randomized sequence
* @returns A randomized sequence of integers from `min` to `max`
* @example
* ```js
* const sequence = SMath.rseq(-2, 2); // [ 2, 0, 1, -2, -1 ]
* ```
* @deprecated Use `SMath.shuffle()` instead
*/
function rseq(min, max) {
min |= 0;
max |= 0;
max++;
var rawData = [];
for (var i = min; i < max; i++) {
rawData.push({ index: runif(-1, 1), value: i });
}
return rawData.sort(function (a, b) { return a.index - b.index; }).map(function (a) { return a.value; });
}
SMath.rseq = rseq;
/**
* Randomize an array of arbitrary elements.

@@ -429,2 +418,3 @@ * @param stack An array of arbitrary elements

* ```js
* const shuffled = SMath.shuffle(['a', 'b', 'c']); // [ 'c', 'a', 'b' ]
* ```

@@ -549,2 +539,44 @@ */

SMath.integrate = integrate;
/**
* Convert an arbitrary decimal number into a simplified fraction (or ratio).
* See `mixed()` for instructions on how to break out the whole number part.
* @param n The decimal number to convert
* @param epsilon Maximum absolute error
* @returns An object containing the fraction's numerator and denominator
* @example
* ```js
* const frac = SMath.rat(0.625); // { num: 5, den: 8 }
* ```
*/
function rat(n, epsilon) {
if (epsilon === void 0) { epsilon = 1e-6; }
var num = 0, den = 1, sign = n < 0 ? -1 : 1;
while (!approx(sign * n, num / den, epsilon)) {
if (sign * n > num / den) {
num++;
}
else {
den++;
}
}
return { num: sign * num, den: den };
}
SMath.rat = rat;
/**
* Convert an arbitrary decimal number into a simplified fraction, after
* breaking out the whole number part first. See `rat()` for keeping the
* number as a ratio without separating the whole number part.
* @param n A decimal number to convert
* @param epsilon Maximum absolute error
* @returns An object containing the whole part and fraction numerator and denominator
* @example
* ```js
* const frac = SMath.mixed(-8 / 6); // { whole: -1, num: 1, den: 3 }
* ```
*/
function mixed(n, epsilon) {
if (epsilon === void 0) { epsilon = 1e-6; }
return __assign({ whole: n | 0 }, rat(n < -1 ? (n | 0) - n : n - (n | 0), epsilon));
}
SMath.mixed = mixed;
})(SMath || (exports.SMath = SMath = {}));
{
"name": "smath",
"version": "1.10.0",
"version": "1.11.0",
"description": "Small math function library",

@@ -55,5 +55,5 @@ "homepage": "https://npm.nicfv.com/",

"devDependencies": {
"@types/node": "22.10.1",
"t6": "1.1.8"
"@types/node": "22.10.5",
"t6": "1.1.9"
}
}

@@ -10,3 +10,3 @@ ## Getting Started

```shell
npx smath
npx smath help
```

@@ -25,1 +25,3 @@

```
> Most `SMath` functions are available through `npx`, except for calculus functions which require a functional argument.

@@ -267,14 +267,2 @@ /**

/**
* Randomize a sequence of integers from `min` to `max`.
* @param min The minimum integer in the randomized sequence
* @param max The maximum integer in the randomized sequence
* @returns A randomized sequence of integers from `min` to `max`
* @example
* ```js
* const sequence = SMath.rseq(-2, 2); // [ 2, 0, 1, -2, -1 ]
* ```
* @deprecated Use `SMath.shuffle()` instead
*/
function rseq(min: number, max: number): Array<number>;
/**
* Randomize an array of arbitrary elements.

@@ -285,2 +273,3 @@ * @param stack An array of arbitrary elements

* ```js
* const shuffled = SMath.shuffle(['a', 'b', 'c']); // [ 'c', 'a', 'b' ]
* ```

@@ -328,2 +317,34 @@ */

function integrate(f: (x: number) => number, a: number, b: number, Ndx?: number): number;
/**
* Convert an arbitrary decimal number into a simplified fraction (or ratio).
* See `mixed()` for instructions on how to break out the whole number part.
* @param n The decimal number to convert
* @param epsilon Maximum absolute error
* @returns An object containing the fraction's numerator and denominator
* @example
* ```js
* const frac = SMath.rat(0.625); // { num: 5, den: 8 }
* ```
*/
function rat(n: number, epsilon?: number): {
num: number;
den: number;
};
/**
* Convert an arbitrary decimal number into a simplified fraction, after
* breaking out the whole number part first. See `rat()` for keeping the
* number as a ratio without separating the whole number part.
* @param n A decimal number to convert
* @param epsilon Maximum absolute error
* @returns An object containing the whole part and fraction numerator and denominator
* @example
* ```js
* const frac = SMath.mixed(-8 / 6); // { whole: -1, num: 1, den: 3 }
* ```
*/
function mixed(n: number, epsilon?: number): {
whole: number;
num: number;
den: number;
};
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc