Mnjs
MATH NODE JS (MNJS): A tiny math library for node.js & JavaScript on browser
Install / Use
/learn @dr-montasir/MnjsREADME
mnjs
MATH NODE JS (MNJS): A tiny math library for node.js & JavaScript on browser
Installation
npm install mnjs
yarn add mnjs
<script src="https://cdn.jsdelivr.net/npm/mnjs/index.js"></script>
Some of the solutions provided by the mnjs library
// JavaScript
0.1 + 0.2 = 0.30000000000000004 // 0.1 + 0.2 === 0.3 returns false
0.2 + 0.7 = 0.8999999999999999 // 0.2 + 0.7 === 0.9 returns false
0.7 - 0.2 = 0.49999999999999994 // 0.7 - 0.2 === 0.5 returns false
0.1 * 0.2 = 0.020000000000000004 // 0.1 * 0.2 === 0.02 returns false
0.3 / 0.1 = 2.9999999999999996 // 0.3 / 0.1 === 3 returns false
1.2 % 0.5 = 0.19999999999999996 // 1.2 / 0.5 === 0.2 returns false
// MNJS library
mnjs.add(0.1, 0.2) = 0.3 // mnjs.add(0.1, 0.2) === 0.3 returns true
mnjs.add(0.2, 0.7) = 0.9 // mnjs.add(0.2, 0.7) === 0.9 returns true
mnjs.subt(0.7, 0.2) = 0.5 // mnjs.subt(0.7, 0.2) === 0.5 returns true
mnjs.mult(0.1, 0.2) = 0.02 // mnjs.mult(0.1, 0.2) === 0.02 returns true
mnjs.divi(0.3, 0.1) = 3 // mnjs.divi(0.3, 0.1) === 3 returns true
mnjs.rem(1.2, 0.5) = 0.2 // mnjs.rem(1.2, 0.5) === 0.2 returns true
<!-- html -->
<!DOCTYPE html>
<html>
<head>
<title>mnjs</title>
<!--<script src="https://cdn.jsdelivr.net/npm/mnjs@4.4.0/index.js"></script>-->
<script src="https://cdn.jsdelivr.net/npm/mnjs/index.min.js"></script>
<!-- This link is the latest mini version ☝ -->
</head>
<body>
<script>
let myNumber = 0.1;
const myCube = mnjs.cube(myNumber);
// mnjs.cube(0.1) returns 0.001
console.log(`(${myNumber})^3 returns ${myCube} in mnjs library`);
// Math.pow(0.1, 3) or (0.1 * 0.1 * 0.1) returns 0.0010000000000000002
console.log(`(${myNumber})^3 returns ${Math.pow(myNumber, 3)} in JavaScript`);
</script>
</body>
</html>
// Next JS
// index.js
// npm install mnjs --save
import mnjs from 'mnjs';
import React from 'react';
const Home = () => {
const price = 4.5 / 3;
return (
<div>
<ul>
<li>{mnjs.add([1,8], 1).[1]}</li>
<li>{mnjs.fix(1, 2)}</li>
<li>{mnjs.fix(mnjs.phi,2)}</li>
<li>{mnjs.stn('8.00')}</li>
<li>{mnjs.zeros(2,2)}</li>
<li>{mnjs.zeros(2.1,2)}</li>
<li>{mnjs.zeros(2.1440000000,2)}</li>
<li>{mnjs.zeros(2.1440000000,5)}</li>
<li>${mnjs.zeros(price,2)}</li>
<li>
<a
className="App-link"
href="https://www.npmjs.com/package/mnjs"
target="_blank"
rel="noopener noreferrer"
>
Learn MNJS (Math Node JS)
</a>
</li>
</ul>
</div>
);
};
export default Home;
// React JS
// App.js
// npm install mnjs --save
import { divi, zeros, stn, nts } from 'mnjs';
import logo from './logo.svg';
import './App.css';
function App() {
const price = divi(4.2, 3);
const priceWithFormat = zeros(price, 2);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">
Learn React
</a>
<br />
<a className="App-link" href="https://www.npmjs.com/package/mnjs" target="_blank" rel="noopener noreferrer">
Learn MNJS (Math Node JS)
</a>
<h2>
<p>${nts(0.0)}</p>
Free ${zeros(stn('0.00'), 2)} <strike>${priceWithFormat}</strike>
</h2>
<small>Type: {typeof priceWithFormat}</small>
</header>
</div>
);
}
export default App;
// Node JS
// index.js
// npm install mnjs --save
// import mnjs from 'mnjs';
// console.log(mnjs.sin.deg(mnjs.range(0, 90, 30)));
// Or
import { sin, range } from 'mnjs';
console.log(sin.deg(range(0, 90, 30)));
Examples
Use
console.log()to output the result.console.log(mnjs.abs(-3.6)); // 3.6
const mnjs = require(`mnjs`);
mnjs.abs(-3.6); // 3.6
mnjs.subt(2, 5); // -3
mnjs.sqr(2) + mnjs.sqrt(4); // 6
mnjs.sqr(4) + mnjs.sqrt(4) / mnjs.pi; // 16.63661977236758
mnjs.e; // 2.718281828459045
mnjs.exp(1); // 2.718281828459045
mnjs.exp(-1); // 0.367879441171442
mnjs.exp(mnjs.pi / 3); // 2.849653908226361
mnjs.log(10); // 2.302585092994046
mnjs.ln2; // 0.693147180559945
mnjs.ln10; // 2.302585092994046
mnjs.log2e; // 1.442695040888963
mnjs.log10e; // 0.434294481903252
mnjs.log1p(5); // 1.791759469228055
mnjs.log(mnjs.e); // 1
mnjs.hypot(4); // 4
mnjs.hypot([4]); // 4
mnjs.hypot(3, 4); // 5
mnjs.hypot([3, 4]); // 5
mnjs.hypot(4, 2, 4); // 6
mnjs.hypot([4, 2, 4]); // 6
mnjs.hypot([-3, -4]); // 5
mnjs.hypot(-3, -4); // 5
mnjs.hypot([-4]); // 4
mnjs.hypot(-4); // 4
mnjs.sqrt(mnjs.add(mnjs.sqr(6), mnjs.sqr(8))) === mnjs.hypot(6, 8); // true
mnjs.hypot([-3, -4], 1); // Error: MNJS ERROR No. 01 : 05
mnjs.hypot([-3, -4], [1]); // Error: MNJS ERROR No. 01 : 05
mnjs.hypot([-3, -4, '1']); // Error: MNJS ERROR No. 01 : 05
mnjs.fix(2.718281828459045, 2); // 2.72
mnjs.inv(10); // 0.1
mnjs.ceil(1.1); // 2
mnjs.ceil(-1.1); // -1
mnjs.ceil([-0.2, 0, 0.2]); // [-0, 0, 1]
mnjs.max(1, 10, 3, -2); // 10
mnjs.max([1, 10, 3, -2]); // 10
mnjs.max(1, 10, 3, ''); // Error: MNJS ERROR No. 01 : 05
mnjs.min(5, 1, -3.2, 0.5, 3); // -3.2
mnjs.min([5, 1, -3.2, 0.5, 3]); // -3.2
mnjs.min(); // Error: MNJS ERROR No. 01 : 05
mnjs.min([]); // Error: MNJS ERROR No. 01 : 05: This function accepts numeric arguments or one numeric array argument. (num1, num2, ..., num) => {} or ([num1, num2, ..., num]) => {}
mnjs.pow(2, 4); // 16
mnjs.pow(2, -2.5); // 0.176776695296637
mnjs.cbrt(8); // 2
mnjs.nrt(0.0001, 4); // 0.1
mnjs.nrt(Infinity, Infinity); // 1
mnjs.nrt(Infinity, Infinity) === mnjs.pow(Infinity, 1 / Infinity); // true
mnjs.tau; // 6.283185307179586
mnjs.sin(1); // 0.841470984807897
mnjs.sin.rad(1); // 0.841470984807897
mnjs.sin(1) === mnjs.sin.rad(1); // true
mnjs.dtr(30); // 0.523598775598299
mnjs.sin.deg(30); // 0.5
mnjs.sin.deg(30) === mnjs.sin(mnjs.dtr(30)); // true
mnjs.cos.deg(60); // 0.5
mnjs.cos(0); // 1
mnjs.cos.rad(0); // 1
mnjs.cos(1) === mnjs.cos.rad(1); // true
mnjs.tan.deg(45); // 1
mnjs.tan(0.5); // 0.54630248984379
mnjs.tan(0.5) === mnjs.tan.rad(0.5); // true
mnjs.tan.deg(90); // -Infinity
1 / mnjs.sin.deg(30); // 2
mnjs.csc.deg(30)(
// 2
1 / mnjs.cos.deg(60)
) === mnjs.sec.deg(60); // true
console.log(mnjs.sec.deg(60))(
// 2
1 / mnjs.tan.deg(45)
) === mnjs.cot.deg(45); // true
mnjs.cot.deg(45); // 1
mnjs.cot.deg(0); // Infinity
mnjs.acsc(mnjs.csc(0.67)); // 0.67
mnjs.asec.rad(1) === mnjs.asec(1); // true
mnjs.stn('123'); // 123
mnjs.nts(123); // "123"
/***** Matrices *****/
mnjs.range(1, 10, 1); // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
mnjs.range(1, 10); // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
mnjs.range(10, 1, 1); // [ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 ]
mnjs.range(10, 1); // [ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 ]
mnjs.range(1, 5, 0.5); // [ 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5 ]
mnjs.range(1, 0, 0.2); // [ 1, 0.8, 0.6, 0.4, 0.2, 0 ]
mnjs.range(10, 1, 2); // [ 10, 8, 6, 4, 2 ]
mnjs.range(-20, 1, 0); // Error: MNJS ERROR No. 02 : 01: The step parameter should not be:
// 1/ null
// 2/ equal or less than zero.
// 3/ greater than the absolute difference between the first and second parameter
mnjs.monolist(1, 5); // [ 1, 1, 1, 1, 1 ]
mnjs.monolist(0.5, 3); // [ 0.5, 0.5, 0.5 ]
mnjs.monolist(0, 5); // [ 0, 0, 0, 0, 0 ]
mnjs.monolist(-0.5, 3); // [ -0.5, -0.5, -0.5 ]
mnjs.monolist(-1, 5); // [ -1, -1, -1, -1, -1 ]
mnjs.monolist(5, 1.1); // RangeError: Invalid array length
// Most of the MNJS functions return a number or an array of numbers
const myArray = mnjs.range(0, 90, 30);
const errArray = [0, 30, '60', 90];
myArray; // [ 0, 30, 60, 90 ]
errArray; // [ 0, 30, '60', 90 ]
mnjs.cube(myArray); // [ 0, 27000, 216000, 729000 ]
mnjs.sin.deg(myArray[1]); // 0.5
mnjs.sin.deg(myArray); // [ 0, 0.5, 0.866025403784439, 1 ]
mnjs.abs(errArray); // Error: MNJS ERROR No. 01: This function accepting either a number or an array.
// In the case of an array, all of its elements must be numbers.
mnjs.dtr(myArray); // [ 0, 0.523598775598299, 1.047197551196598, 1.570796326794897 ]
// Note the result may change in some functions depending on the position of the arguments
mnjs.add(2, 2); // 4
mnjs.add([0, 2], [4, 8]); // [ 4, 10 ]
mnjs.add([4, 8], [0, 2]); // [ 4, 10 ]
mnjs.add(2, [1, 2]); // [ 3, 4 ]
mnjs.add([1, 2], 2); // [ 3, 4 ]
mnjs.subt(2, [1, 2]); // [ 1, 0 ]
mnjs.subt([1, 2], 2); // [ -1, 0 ]
mnjs.subt([0, 2], [4, 8]); // [ -4, -6 ]
mnjs.subt([4, 8], [0, 2]); // [ 4, 6 ]
mnjs.mult(2, [1, 2]); // [ 2, 4 ]
mnjs.mult([1, 2], 2); // [ 2,
Related Skills
bluebubbles
346.8kUse when you need to send or manage iMessages via BlueBubbles (recommended iMessage integration). Calls go through the generic message tool with channel="bluebubbles".
slack
346.8kUse when you need to control Slack from OpenClaw via the slack tool, including reacting to messages or pinning/unpinning items in Slack channels or DMs.
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
107.6kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.



