{"id":18400115,"url":"https://github.com/maz01001/math-js","last_synced_at":"2025-04-07T05:35:12.078Z","repository":{"id":37256655,"uuid":"352442457","full_name":"MAZ01001/Math-Js","owner":"MAZ01001","description":"some math-related js classes and possibly more","archived":false,"fork":false,"pushed_at":"2024-08-16T05:45:16.000Z","size":547,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-16T06:44:05.246Z","etag":null,"topics":["base-conversion","chainable-methods","class","complex-numbers","formula","fraction","greatest-common-divisor","integer-division","javascript","linear-algebra","math","matrix","matrix-inversion","modulo-operation","polynomial","vector"],"latest_commit_sha":null,"homepage":"https://maz01001.github.io/Math-Js/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MAZ01001.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-28T21:28:02.000Z","updated_at":"2024-08-16T05:45:19.000Z","dependencies_parsed_at":"2024-08-16T06:54:57.833Z","dependency_job_id":null,"html_url":"https://github.com/MAZ01001/Math-Js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAZ01001%2FMath-Js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAZ01001%2FMath-Js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAZ01001%2FMath-Js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAZ01001%2FMath-Js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MAZ01001","download_url":"https://codeload.github.com/MAZ01001/Math-Js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223272780,"owners_count":17117677,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["base-conversion","chainable-methods","class","complex-numbers","formula","fraction","greatest-common-divisor","integer-division","javascript","linear-algebra","math","matrix","matrix-inversion","modulo-operation","polynomial","vector"],"created_at":"2024-11-06T02:29:53.112Z","updated_at":"2024-11-06T02:29:53.998Z","avatar_url":"https://github.com/MAZ01001.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Math in JavaScript\n\n- [Polynomial.js](#polynomialjs)\n- [Fraction.js](#fractionjs)\n- [Matrix.js](#matrixjs)\n- [Vector.js](#vectorjs)\n- [ComplexNumber.js](#complexnumberjs)\n- [BigIntType.js](#biginttypejs)\n- [BigIntFractionComplex.js](#bigintfractioncomplexjs)\n- [RNG.js](#rngjs)\n- [functions.js](#functionsjs)\n\n----\n\n## [Polynomial.js](./Polynomial.js)\n\n\u003e WIP\n\u003e\n\u003e - formula for degree 3/4\n\u003e - chainable methods\n\n- make polynomial directly/from string/roots\n- print as string\n- finding roots\n  - Newton's method for degree 3 and higher\n  - formula for degree 2 and lower\n- create derivative/antiderivative\n- calculate f(x)\n- calculate integral with\n  - antiderivative formula\n  - set delta x\n\nScroll [UP](#polynomialjs \"Scroll to start of section: Polynomial.js\")\n    | [TOP](#math-in-javascript \"Scroll to top of document: Math in JavaScript\")\n\n## [Fraction.js](./Fraction.js)\n\n- make fraction directly/from decimal/-string\n- GCD \u0026 decimal to fraction algorithm as public static methods\n- fraction to\n  - improper-form\n  - mixed-form\n  - decimal\n  - string\n- addition/multiplication/subtraction/divition with\n  - a single integer\n  - another fraction\n- raise fraction to nth power\n- chainable methods\n\nScroll [UP](#fractionjs \"Scroll to start of section: Fraction.js\")\n    | [TOP](#math-in-javascript \"Scroll to top of document: Math in JavaScript\")\n\n## [Matrix.js](./Matrix.js)\n\n\u003e WIP\n\u003e\n\u003e - row to row addition\n\u003e - row to row subtraction\n\u003e - row multiplied by constant\n\n- make matrix directly/from string\n- create identity matrix\n- print as a formatted string\n- single number\n  - muliplication\n  - divition\n- matrix\n  - addition\n  - subtraction\n  - multiplication\n  - divition\n- matrix inversion (Gauß Bareiss)\n- chainable methods\n- row\n  - move\n  - delete\n- col\n  - delete\n- check matrix stats\n\nScroll [UP](#matrixjs \"Scroll to start of section: Matrix.js\")\n    | [TOP](#math-in-javascript \"Scroll to top of document: Math in JavaScript\")\n\n## [Vector.js](./Vector.js)\n\n\u003e WIP\n\u003e\n\u003e - make vector from string\n\u003e - printing to string\n\n- 1D, 2D or 3D vector\n- calculate length\n- calculate angle\n  - to other vector\n  - to X, Y, Z - axis\n  - to XY, YZ, XZ - plane\n  - to X, Y, Z - axis on XY, YZ, XZ - plane (2D\u003e3D)\n- static methods DEG to RAD and RAD to DEG conversion\n- test if finite\n- test if equal to another vector\n- convert vector to unit-vector (length 1 same direction)\n- vector\n  - addition\n  - subtraction\n  - inversion\n  - scale by constant (multiply number)\n\nScroll [UP](#vectorjs \"Scroll to start of section: Vector.js\")\n    | [TOP](#math-in-javascript \"Scroll to top of document: Math in JavaScript\")\n\n## [ComplexNumber.js](./ComplexNumber.js)\n\n\u003e WIP\n\u003e\n\u003e - pow (without polar form) better calculation and support for non-integers\n\u003e - pow with complex exponent `z↑z`\n\u003e - root (any index) without polar form\n\u003e - root with complex index\n\u003e - log of complex numbers (with custom base)\n\n- static (precalculated) values\n  - RegExp for cartesian (`a±bi`) and polar form (`r∠φrad` or `r∠φ°`)\n    - `∠` is U+2220 and `°` is U+00B0\n  - `2π` ie `τ`\n  - `π/2`\n  - `π/4`\n  - factor to convert from radians to degrees (`180/π`)\n  - factor to convert from degrees to radians (`π/180`)\n- create new complex numbers\n  - from (getter) `0`, `1`, `i`, `e↑i`, or `i↑i`\n  - from real and imaginary parts (constructor with `new` and alias without `new`)\n  - from length and angle (from positive real axis in radians)\n  - from angle (from positive real axis in radians) on unit circle\n  - from the square root of any real number\n  - from `e↑(i*n)` where `n` is a real number\n  - from `n^i` where `n` is a real number (except `0`)\n  - from logarithm with custom base (except `0` and `1`) from any real number (except `0`)\n  - from string in format `a±bi` or `r∠φrad` (or degrees `r∠φ°`)\n    - `∠` is U+2220 and `°` is U+00B0\n- attributes (non-private)\n  - real part (JS `Number`)\n  - imaginary part (JS `Number`)\n- internal methods (non-private)\n  - calculate greatest common divisor of two positive safe integers (`[1..2↑53[`)\n  - round float to nearest integer when closer than float minimum (JS `Number.EPSILON*5`)\n- round complex number (real and imaginary part separately) to nearest integer when closer than float minimum (JS `Number.EPSILON*5`)\n  - useful for trigonometric functions as they calculate with small numbers and are thereby prone to float precision errors (noted in JSDoc of affected methods)\n- getter\n  - absolute value / length / radius\n  - angle from polar coordinates (from positive real axis in radians)\n    - `[0,2π[` / `undefined`\n    - _safe_ `[0,2π[` / `0`\n    - _small_ `]-π,π]` / `undefined`\n    - _small and safe_ `]-π,π]` / `0`\n  - arc length _from positive real axis to the complex number in polar coordinates_\n  - sector (arc area) _from positive real axis to the complex number in polar coordinates_\n- convert to string in format `a±bi` or `r∠φrad` (or degrees `r∠φ°`)\n  - `∠` is U+2220 and `°` is U+00B0\n- log current value to console without breaking method chain\n  - format: `±a + (±b)i ~ r ∠ φ rad (φ°)`\n    - `∠` is U+2220 and `°` is U+00B0\n- copy values\n  - from the current to a new complex number (create a copy)\n  - from another to the current complex number (override)\n  - from the current to another complex number (reverse override)\n- check for equality to `0`, `1`, or another complex number\n- arithmetic with complex numbers\n  - negate current complex number (`z*(-1)` ie `-z`)\n  - invert current complex number (`z↑(-1)` ie `1/z`)\n  - conjugate of current complex number (`a+bi` → `a-bi`)\n  - rotate complex number (counterclockwise) by an angle (from positive real axis in radians)\n  - scale angle by a scaler (real number)\n  - addition with a real number or another complex number\n  - subtraction with a real number or another complex number\n  - multiplication with a real number or another complex number\n  - division with a real number or another complex number\n  - raising to `n`th power\n    - with kartesian form (currently only safe integers `]-2↑53..2↑53[`)\n    - with polar form (lower precision but faster and not limited to integers)\n  - square root (\"positive\" solution to `z↑2`)\n- `n`th root (currently only safe integers `]-2↑53..2↑53[`)\n  - gives a generator that creates all complex solutions to `z↑n`\n  - ordered counterclockwise from positive real axis\n  - assume first entry is the \"positive\" root ie. principal root\n\n  ```javascript\n  new ComplexNumber(2,0).pow(-4).roots(-4).next().value?.roundEpsilon().toString()??\"no root\";\n  //=\u003e \"2+0i\"\n  [...new ComplexNumber(2,0).pow(-4).roots(-4)].map(v=\u003ev.roundEpsilon().toString());\n  //=\u003e [\"2+0i\", \"0+2i\", \"-2+0i\", \"0-2i\"]\n  ```\n\nthe class and its prototype are immutable!\n\n- import [dynamically](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import \"MDN JS import() / dynamic import\")\n\n  ```javascript\n  const { ComplexNumber } = await import(\"./ComplexNumber.js\");\n  ```\n\n- import in node.js\n\n  ```javascript\n  const { ComplexNumber } = require(\"./ComplexNumber.js\");\n  // or in modules ↓\n  import { ComplexNumber } from \"./ComplexNumber.js\";\n  ```\n\n- import in html:\n\n  ```html\n  \u003cscript src=\"./ComplexNumber.js\"\u003e\u003c/script\u003e\n  ```\n\nScroll [UP](#complexnumberjs \"Scroll to start of section: ComplexNumber.js\")\n    | [TOP](#math-in-javascript \"Scroll to top of document: Math in JavaScript\")\n\n## [BigIntType.js](./BigIntType.js)\n\n\u003e WIP\n\u003e\n\u003e - custom PRNG for `randomInt()`\n\u003e - `BigIntType` as type for bitshift methods\n\u003e - new special case for internal division algorithm\n\narbitrary precision integer using JS's Uint8Array (unsigned 8-bit integer array)\nhuman \"readable\" code with lots of documentation (js-doc \u0026 some comments) and descriptive error throws\n\n\u003e [__BigIntType online calculator__ WIP](https://maz01001.github.io/site/biginttype_calc)\n\n- adjustable limit `MAX_SIZE:Number` (Range 1 to 67108864 / 64MiB) (software max is [8PiB-1] - which could be extended to [16PiB-2] using `Uint16Array` - or even [32PiB-4] using `Uint32Array` and `BigInt`)\n- internal values: `sign:Boolean` / `digits:Uint8Array` (base 256 digits) / `length:Number` (length of digit-array)\n- during [JS type coercion](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#type_coercion \"MDN reference on type coercion in JS\"), it converts to `BigInt` by default or in the context of numbers and to (base 16) `String` when used in the context of strings\n- conversions to `toBigInt()` / `ToNumber()` / `ToString(base)`\n- can be created from, and converted to, different [bases](#biginttypejs-supported-numerical-bases \"scroll down to see more info on the supported numerical bases\")\n- encode `toURL()` / `fromURL()`\n- comparisons:\n  - `isOdd()` / `isEven()`\n  - `A === 0` / `A === 1` / `A === 2`\n  - `A \u003c B` / `A \u003e B` / `A == B` / `A === B` / `A \u003e= B` / `A \u003c= B`\n  - `isSafeInteger()` / `isFinite()` (for checking if its save to convert to `Number`)\n  - `isPowerOfTwo()` / `isPowerOfBase()` (256)\n- chainable methods:\n  - number constants: `0` / `1` / `2` also negative equivalents and `Infinity` (`1 ** 1024`) / `MAX_VALUE` / `HelloThere`\n  - logging to console via `logConsole(base)` format: `[timestamp] (byte count) sign digits (base indicator)` (text is green on black and in large monospace font if the console supports it)\n  - copy/setEqual: `copy()` / `reverseCopy(toOtherNumber)` / `setEqualTo(otherNumber)` / `swapWith(otherNumber)`\n  - sign: `abs()` / `neg()` (`-A`) / `signNum()` (+1 / +0 / -1)\n  - operations:\n    - `++A` / `--A` / `A += B` / `A -= B`\n    - `A *= B` using karatsubas algorithm / `A **= B`\n    - `A /= B` with [rounding](#biginttypejs-supported-rounding-types \"scroll down to see more info on the supported rounding types\") / `A %= B` with [rounding](#biginttypejs-supported-modulo-types \"scroll down to see more info on the supported modulo types\")\n    - `A *= 2` / `A /= 2` with [rounding](#biginttypejs-supported-rounding-types \"scroll down to see more info on the supported rounding types\")\n    - `A *= (256 ** x)` with [rounding](#biginttypejs-supported-rounding-types \"scroll down to see more info on the supported rounding types\") - (digit-shifts)\n    - `A **= 2` / `A **= 3`\n  - bitwise operations:\n    - `A \u003e\u003e\u003e= x` / `A \u003c\u003c= x` / `A \u0026= B` / `A |= B` / `A ^= B` / `A ~= A`\n  - `GCD(A, B)`\n  - `mapRange(a, b, a2, b2)` with [rounding](#biginttypejs-supported-rounding-types \"scroll down to see more info on the supported rounding types\") and limit (cap at a2 / b2)\n- `randomInt(min, max)` (using `Math.random()`)\n- _↑ (`A` and `B` are type `BigIntType` and `x` is type `Number`) ↑_\n\n\u003cdetails closed\u003e\u003csummary id=\"biginttypejs-supported-numerical-bases\"\u003e\u003cb\u003eSupported numerical bases\u003c/b\u003e\u003c/summary\u003e\n\n\u003e ALL YOUR BASE ARE BELONG TO US\n\n- all bases from 2 to 4'294'967'296 (inclusive) are supported for in- and output\n  - via `String`, `Number`, `BigInt`, `Uint8Array`, or array of `Number`s\n  - base 1 is only supported for input\n- supported prefixes\n  - `0b` for base 2 (binary)\n  - `0o` for base 8 (octal)\n  - `0x` for base 16 (hexadecimal)\n- used characters (as digits in a string)\n  - up to base 36 (including), `0-9` and `A-Z` are used as needed\n  - above 36 only via CSV (comma-separated-values or numbers in this case),\n    where each number corresponds to the numerical value of the digit at that place\n    (in base 10 / with `0-9`)\n  - `\"braille\"` is in base 256 but uses braille patterns (`U+2800` to `U+28FF` inclusive) as digit-charset\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"biginttypejs-supported-numerical-base-names\"\u003e\u003cb\u003eSupported numerical base names\u003c/b\u003e\u003c/summary\u003e\n\n\u003e [Wikipedia: Numerical Bases](https://en.wikipedia.org/wiki/List_of_numeral_systems#Standard_positional_numeral_systems)\n\n| base | names                                                |       base | names                                          |\n| ----:| ---------------------------------------------------- | ----------:| ---------------------------------------------- |\n|    2 | `b` / `bin` / `bits` / `binary` / `1bit`             |         72 | `duoseptuagesimal`                             |\n|    3 | `ternary` / `trinary`                                |         80 | `octogesimal`                                  |\n|    4 | `q` / `quaternary` / `2bit`                          |         81 | `unoctogesimal`                                |\n|    5 | `quinary` / `pental`                                 |         85 | `pentoctogesimal`                              |\n|    6 | `senary` / `heximal` / `seximal`                     |         89 | `enneaoctogesimal`                             |\n|    7 | `septenary`                                          |         90 | `nonagesimal`                                  |\n|    8 | `o` / `oct` / `octal` / `3bit`                       |         91 | `unnonagesimal`                                |\n|    9 | `nonary`                                             |         92 | `duononagesimal`                               |\n|   10 | `d` / `dec` / `decimal` / `denary`                   |         93 | `trinonagesimal`                               |\n|   11 | `undecimal`                                          |         94 | `tetranonagesimal`                             |\n|   12 | `duodecimal` / `dozenal` / `uncial`                  |         95 | `pentanonagesimal`                             |\n|   13 | `tridecimal`                                         |         96 | `hexanonagesimal`                              |\n|   14 | `tetradecimal`                                       |         97 | `septanonagesimal`                             |\n|   15 | `pentadecimal`                                       |        100 | `centesimal`                                   |\n|   16 | `h` / `hex` / `hexadecimal` / `sexadecimal` / `4bit` |        120 | `centevigesimal`                               |\n|   17 | `heptadecimal`                                       |        121 | `centeunvigesimal`                             |\n|   18 | `octodecimal`                                        |        125 | `centepentavigesimal`                          |\n|   19 | `enneadecimal`                                       |        128 | `centeoctovigesimal` / `7bit`                  |\n|   20 | `vigesimal`                                          |        144 | `centetetraquadragesimal`                      |\n|   21 | `unvigesimal`                                        |        169 | `centenovemsexagesimal`                        |\n|   22 | `duovigesimal`                                       |        185 | `centepentoctogesimal`                         |\n|   23 | `trivigesimal`                                       |        196 | `centehexanonagesimal`                         |\n|   24 | `tetravigesimal`                                     |        200 | `duocentesimal`                                |\n|   25 | `pentavigesimal`                                     |        210 | `duocentedecimal`                              |\n|   26 | `hexavigesimal`                                      |        216 | `duocentehexidecimal`                          |\n|   27 | `heptavigesimal` / `septemvigesimal`                 |        225 | `duocentepentavigesimal`                       |\n|   28 | `octovigesimal`                                      |        256 | `duocentehexaquinquagesimal` / `byte` / `8bit` |\n|   29 | `enneavigesimal`                                     |        300 | `trecentesimal`                                |\n|   30 | `trigesimal`                                         |        360 | `trecentosexagesimal`                          |\n|   31 | `untrigesimal`                                       |        512 | `9bit`                                         |\n|   32 | `duotrigesimal` / `5bit`                             |       1024 | `10bit`                                        |\n|   33 | `tritrigesimal`                                      |       2048 | `11bit`                                        |\n|   34 | `tetratrigesimal`                                    |       4096 | `12bit`                                        |\n|   35 | `pentatrigesimal`                                    |       8192 | `13bit`                                        |\n|   36 | `t` / `txt` / `text` / `hexatrigesimal`              |      16384 | `14bit`                                        |\n|   37 | `heptatrigesimal`                                    |      32768 | `15bit`                                        |\n|   38 | `octotrigesimal`                                     |      65536 | `16bit`                                        |\n|   39 | `enneatrigesimal`                                    |     131072 | `17bit`                                        |\n|   40 | `quadragesimal`                                      |     262144 | `18bit`                                        |\n|   42 | `duoquadragesimal`                                   |     524288 | `19bit`                                        |\n|   45 | `pentaquadragesimal`                                 |    1048576 | `20bit`                                        |\n|   47 | `septaquadragesimal`                                 |    2097152 | `21bit`                                        |\n|   48 | `octoquadragesimal`                                  |    4194304 | `22bit`                                        |\n|   49 | `enneaquadragesimal`                                 |    8388608 | `23bit`                                        |\n|   50 | `quinquagesimal`                                     |   16777216 | `24bit`                                        |\n|   52 | `duoquinquagesimal`                                  |   33554432 | `25bit`                                        |\n|   54 | `tetraquinquagesimal`                                |   67108864 | `26bit`                                        |\n|   56 | `hexaquinquagesimal`                                 |  134217728 | `27bit`                                        |\n|   57 | `heptaquinquagesimal`                                |  268435456 | `28bit`                                        |\n|   58 | `octoquinquagesimal`                                 |  536870912 | `29bit`                                        |\n|   60 | `sexagesimal` / `sexagenary`                         | 1073741824 | `30bit`                                        |\n|   62 | `duosexagesimal`                                     | 2147483648 | `31bit`                                        |\n|   64 | `tetrasexagesimal` / `6bit`                          | 4294967296 | `32bit`                                        |\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"biginttypejs-supported-rounding-types\"\u003e\u003cb\u003eSupported rounding types\u003c/b\u003e\u003c/summary\u003e\n\n\u003e [![Wikipedia: Rounding (interactible graph)](https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Comparison_rounding_graphs_SMIL.svg/300px-Comparison_rounding_graphs_SMIL.svg.png \"Wikipedia: Rounding (interactible graph)\")](https://en.wikipedia.org/wiki/Rounding)\n\n| name        | description                                 |                       example                       |\n| ----------- | ------------------------------------------- |:---------------------------------------------------:|\n| `NEAR_DOWN` | round to nearest integer, towards -infinity |       +1.5 → +1 \u003cbr\u003e +2.5 → +2 \u003cbr\u003e −2.5 → −3       |\n| `NEAR_UP`   | round to nearest integer, towards +infinity |       +1.5 → +2 \u003cbr\u003e +2.5 → +3 \u003cbr\u003e −2.5 → −2       |\n| `NEAR_ZERO` | round to nearest integer, towards zero      |       +1.5 → +1 \u003cbr\u003e +2.5 → +2 \u003cbr\u003e −2.5 → −2       |\n| `NEAR_INF`  | round to nearest integer, away from zero    |       +1.5 → +2 \u003cbr\u003e +2.5 → +3 \u003cbr\u003e −2.5 → −3       |\n| `NEAR_EVEN` | round to nearest even integer               |       +1.5 → +2 \u003cbr\u003e +2.5 → +2 \u003cbr\u003e −2.5 → −2       |\n| `NEAR_ODD`  | round to nearest odd integer                |       +1.5 → +1 \u003cbr\u003e +2.5 → +3 \u003cbr\u003e −2.5 → −3       |\n| `FLOOR`     | round down (towards -infinity)              | +1.\u0026ast; → +1 \u003cbr\u003e +2.\u0026ast; → +2 \u003cbr\u003e −2.\u0026ast; → −3 |\n| `CEIL`      | round up (towards +infinity)                | +1.\u0026ast; → +2 \u003cbr\u003e +2.\u0026ast; → +3 \u003cbr\u003e −2.\u0026ast; → −2 |\n| `TRUNC`     | round down (towards zero)                   | +1.\u0026ast; → +1 \u003cbr\u003e +2.\u0026ast; → +2 \u003cbr\u003e −2.\u0026ast; → −2 |\n| `RAISE`     | round up (away from zero)                   | +1.\u0026ast; → +2 \u003cbr\u003e +2.\u0026ast; → +3 \u003cbr\u003e −2.\u0026ast; → −3 |\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"biginttypejs-supported-modulo-types\"\u003e\u003cb\u003eSupported modulo types\u003c/b\u003e\u003c/summary\u003e\n\n\u003e [Wikipedia: Modulo](https://en.wikipedia.org/wiki/Modulo)\n\n| name              | description                              |\n| ----------------- | ---------------------------------------- |\n| `ROUND_NEAR_DOWN` | division rounded towards -infinity       |\n| `ROUND_NEAR_UP`   | division rounded towards +infinity       |\n| `ROUND_NEAR_ZERO` | division rounded towards zero            |\n| `ROUND_NEAR_INF`  | division rounded away from zero          |\n| `ROUND_NEAR_EVEN` | division rounded to nearest even integer |\n| `ROUND_NEAR_ODD`  | division rounded to nearest odd integer  |\n| `FLOOR`           | floored division (towards -infinity)     |\n| `CEIL`            | ceiled division (towards +infinity)      |\n| `TRUNC`           | truncated division (towards zero)        |\n| `RAISE`           | raised division (away from zero)         |\n| `EUCLID`          | euclidean division (positive remainder)  |\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"biginttypejs-modulo-examples\"\u003e\u003cb\u003eModulo examples\u003c/b\u003e\u003c/summary\u003e\n\n$\\large3\\bmod5\\implies\\frac35=0\\frac35=0.6\\qquad\\text{round up}$\n\n|         | trunc | floor | euclid | round | ceil | raise |\n|:-------:| -----:| -----:| ------:| -----:| ----:| -----:|\n| +3 % +5 |    +3 |    +3 |     +3 |    −2 |   −2 |    −2 |\n| +3 % −5 |    +3 |    −2 |     +3 |    −2 |   +3 |    −2 |\n| −3 % +5 |    −3 |    +2 |     +2 |    +2 |   −3 |    +2 |\n| −3 % −5 |    −3 |    −3 |     +2 |    +2 |   +2 |    +2 |\n\n\u003cbr\u003e\n\n$\\large5\\bmod3\\implies\\frac53=1\\frac23=1.\\overline6\\qquad\\text{round up}$\n\n|         | trunc | floor | euclid | round | ceil | raise |\n|:-------:| -----:| -----:| ------:| -----:| ----:| -----:|\n| +5 % +3 |    +2 |    +2 |     +2 |    −1 |   −1 |    −1 |\n| +5 % −3 |    +2 |    −1 |     +2 |    −1 |   +2 |    −1 |\n| −5 % +3 |    −2 |    +1 |     +1 |    +1 |   −2 |    +1 |\n| −5 % −3 |    −2 |    −2 |     +1 |    +1 |   +1 |    +1 |\n\n\u003cbr\u003e\n\n$\\large4\\bmod3\\implies\\frac43=1\\frac13=1.\\overline3\\qquad\\text{round down}$\n\n|         | trunc | floor | euclid | round | ceil | raise |\n|:-------:| -----:| -----:| ------:| -----:| ----:| -----:|\n| +4 % +3 |    +1 |    +1 |     +1 |    +1 |   −2 |    −2 |\n| +4 % −3 |    +1 |    −2 |     +1 |    +1 |   +1 |    −2 |\n| −4 % +3 |    −1 |    +2 |     +2 |    −1 |   −1 |    +2 |\n| −4 % −3 |    −1 |    −1 |     +2 |    −1 |   +2 |    +2 |\n\n\u003cbr\u003e\n\n$\\large3\\bmod2\\implies\\frac32=1\\frac12=1.5\\qquad\\text{round down or up }\\normalsize\\text{(depending on rounding type)}$\n\n|         | trunc | floor | euclid |                    round                   | ceil | raise |\n|:-------:| -----:| -----:| ------:|:------------------------------------------:| ----:| -----:|\n| +3 % +2 |    +1 |    +1 |     +1 | \u0026lfloor; −1 \u0026rfloor; or \u0026lceil; +1 \u0026rceil; |   −1 |    −1 |\n| +3 % −2 |    +1 |    −1 |     +1 | \u0026lfloor; −1 \u0026rfloor; or \u0026lceil; +1 \u0026rceil; |   +1 |    −1 |\n| −3 % +2 |    −1 |    +1 |     +1 | \u0026lfloor; +1 \u0026rfloor; or \u0026lceil; −1 \u0026rceil; |   −1 |    +1 |\n| −3 % −2 |    −1 |    −1 |     +1 | \u0026lfloor; +1 \u0026rfloor; or \u0026lceil; −1 \u0026rceil; |   +1 |    +1 |\n\n\u003cbr\u003e\n\n$\\large3\\bmod3\\implies\\frac33=1\\frac03=1.0\\qquad\\text{round 0 }\\normalsize\\text{(same as rounding down)}$\n\n|         | trunc | floor | euclid | round | ceil | raise |\n|:-------:| -----:| -----:| ------:| -----:| ----:| -----:|\n| +3 % +3 |    +0 |    +0 |     +0 |    +0 |   −0 |    −0 |\n| +3 % −3 |    +0 |    −0 |     +0 |    +0 |   +0 |    −0 |\n| −3 % +3 |    −0 |    +0 |     +0 |    −0 |   −0 |    +0 |\n| −3 % −3 |    −0 |    −0 |     +0 |    −0 |   +0 |    +0 |\n\n\u003c/details\u003e\n\n_more details/documentation in the file itself via js-docs (`/** */`) and additional commenting with `//~`_\n\nScroll [UP](#biginttypejs \"Scroll to start of section: BigIntType.js\")\n    | [TOP](#math-in-javascript \"Scroll to top of document: Math in JavaScript\")\n\n## [BigIntFractionComplex.js](./BigIntFractionComplex.js)\n\n\u003e WIP\n\u003e\n\u003e idea: BigInt \u003e\u003e Fraction \u0026 Infinity \u003e\u003e ComplexNumber\n\nScroll [UP](#bigintfractioncomplexjs \"Scroll to start of section: BigIntFractionComplex.js\")\n    | [TOP](#math-in-javascript \"Scroll to top of document: Math in JavaScript\")\n\n## [RNG.js](./RNG.js)\n\nRNG stuff\n\n\u003e WIP\n\u003e\n\u003e - voronoi noise\n\u003e - perlin noise\n\nStatic methods for `RNG.noise(x, seed)` (non-cryptographic 32bit hash) and `RNG.valueNoise2D(x, y, seed)`.\n\nAfter instanciating an RNG object (`sfc32`) with a seed (`MurmurHash3`) one can get random values via:\n\n- `val32` gives a random 32bit unsigned integer\n- `val` gives a random float 0 to 1 (both inclusive)\n- `dec` gives a random decimal 0 to 1 (exclusive 1)\n- `bool` gives a random boolean value\n- `range(min, max)` gives a random float within the given range (both inclusive)\n\nThe RNG state (from an instance) can be saved via `state` and later restored via `RNG.from(state)`.\n\nInternal but non-private methods:\n\n- `RNG._hash_(str)` creates a 128bit hash via `MurmurHash3` (non-cryptographic)\n- `RNG._qLerp_(a, b, t)` quintic interpolation used by `valueNoise2D`\n\nThe class and its prototype are immutable!\n\n\u003cdetails closed\u003e\u003csummary\u003eImport\u003c/summary\u003e\n\n- import [dynamically](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import \"MDN JS import() / dynamic import\")\n\n  ```javascript\n  const { RNG } = await import(\"./RNG.js\");\n  ```\n\n- import in node.js\n\n  ```javascript\n  const { RNG } = require(\"./RNG.js\");\n  // or in modules ↓\n  import { RNG } from \"./RNG.js\";\n  ```\n\n- import in html:\n\n  ```html\n  \u003cscript src=\"./RNG.js\"\u003e\u003c/script\u003e\n  ```\n\n\u003c/details\u003e\n\nTest render with `valueNoise2D`: \u003chttps://maz01001.github.io/Math-Js/RNG_example.html\u003e\n\n\u003cdetails closed\u003e\u003csummary\u003ePerformance test\u003c/summary\u003e\n\n\u003e node.js `v16.13.1` on intel `i7-10700K`\n\n```javascript\nnew RNG();new RNG();new RNG();//! warmup\nconst a=performance.now();\nconst rng=new RNG();\nconst b=performance.now();\nrng.val32;\nconst c=performance.now();\n{\n    const rng=new RNG();\n    for(let i=0;i\u003c10000;++i)rng.val32;\n}\nconst d=performance.now();\nnew RNG().val32;\nconst e=performance.now();\nfor(let i=0;i\u003c1000;++i){new RNG(\"Lorem\").val32;new RNG(\"ipsum\").val32;new RNG(\"dolor\").val32;new RNG(\"sit\").val32;new RNG(\"amet\").val32;new RNG(\"consectetur\").val32;new RNG(\"adipiscing\").val32;new RNG(\"elit\").val32;new RNG(\"Terram\").val32;new RNG(\"mihi\").val32;}\nconst f=performance.now();\nfor(let i=0;i\u003c10000;++i)new RNG(\"\"+i).val32;\nconst g=performance.now();\nRNG.noise(0x3FA98E75);\nconst h=performance.now();\nfor(let i=0;i\u003c1000;++i){RNG.noise(0x3FA98E75);RNG.noise(0x16D9FCA5);RNG.noise(0x1C7590AF);RNG.noise(0x28C6E13D);RNG.noise(0x2CA6DF15);RNG.noise(0x4E0C719F);RNG.noise(0x5237A8B1);RNG.noise(0xD7F3E9AB);RNG.noise(0xF21D5409);RNG.noise(0xF93C5AEB);}\nconst i=performance.now();\nfor(let i=0;i\u003c10000;++i)RNG.noise(i);\nconst j=performance.now();\nfor(let i=0;i\u003c10000;++i)RNG.valueNoise2D(i,i*0xF47A23);\nconst k=performance.now();\nconsole.log([\n    `                     init new RNG: ${(b-a).toFixed(4).padStart(9)} ms`,//=\u003e    0.0150 ms\n    `                            val32: ${(c-b).toFixed(4).padStart(9)} ms`,//=\u003e    0.0285 ms\n    `              init + 10'000 val32: ${(d-c).toFixed(4).padStart(9)} ms`,//=\u003e    1.8899 ms\n    `                       init val32: ${(e-d).toFixed(4).padStart(9)} ms`,//=\u003e    0.0218 ms\n    `             1000 * 10 init val32: ${(f-e).toFixed(4).padStart(9)} ms`,//=\u003e   10.0103 ms\n    `                10'000 init val32: ${(g-f).toFixed(4).padStart(9)} ms`,//=\u003e    5.5522 ms\n    `                      prime noise: ${(h-g).toFixed(4).padStart(9)} ms`,//=\u003e    0.0781 ms\n    `            1000 * 10 prime noise: ${(i-h).toFixed(4).padStart(9)} ms`,//=\u003e    1.7489 ms\n    `             10'000 counter noise: ${(j-i).toFixed(4).padStart(9)} ms`,//=\u003e    0.2728 ms\n    `10'000 counter+prime valueNoise2D: ${(k-j).toFixed(4).padStart(9)} ms`,//=\u003e    4.4087 ms\n    `                            TOTAL: ${(k-a).toFixed(4).padStart(9)} ms`,//=\u003e   24.0262 ms\n].join(\"\\n\"));\n```\n\n\u003c/details\u003e\n\nScroll [UP](#rngjs \"Scroll to start of section: RNG.js\")\n    | [TOP](#math-in-javascript \"Scroll to top of document: Math in JavaScript\")\n\n## [functions.js](./functions.js)\n\nsome useful math functions\n\n\u003e also see [`other-projects/useful.js`](https://github.com/MAZ01001/other-projects#usefuljs)\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-mapRange\"\u003e\u003ccode\u003emapRange\u003c/code\u003e\u003c/summary\u003e\n\ntranslate the given number to another range\n\n```typescript\nfunction mapRange(n: number, a: number, b: number, x: number, y: number, limit?: boolean | undefined): number\nmapRange(0.5, 0, 1, 0, 100); //=\u003e 50\nmapRange(3, 0, 1, 0, 100); //=\u003e 300\nmapRange(3, 0, 1, 0, 100, true); //=\u003e 100\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-toPercent\"\u003e\u003ccode\u003etoPercent\u003c/code\u003e\u003c/summary\u003e\n\ncalculates the percentage of the given number within the given range\n\n```typescript\nfunction toPercent(n: number, x: number, y: number): number\ntoPercent(150, 100, 200); //=\u003e 0.5 = 50%\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-deg2rad\"\u003e\u003ccode\u003edeg2rad\u003c/code\u003e\u003c/summary\u003e\n\nconverts the given angle from DEG to RAD\n\n```typescript\nfunction deg2rad(deg: number): number\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-rad2deg\"\u003e\u003ccode\u003erad2deg\u003c/code\u003e\u003c/summary\u003e\n\nconverts the given angle from RAD to DEG\n\n```typescript\nfunction rad2deg(rad: number): number\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-gcd\"\u003e\u003ccode\u003egcd\u003c/code\u003e\u003c/summary\u003e\n\ncalculates the greatest common divisor of `n` and `m` (positive safe integers `[1..2↑53[`)\n\n```typescript\nfunction gcd(n: number, m: number): number\ngcd(45, 100); //=\u003e 5 → (45/5) / (100/5) → 9/20\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-dec2frac\"\u003e\u003ccode\u003edec2frac\u003c/code\u003e\u003c/summary\u003e\n\nconverts a decimal number to an improper-fraction (rough estimation)\n\n```typescript\nfunction dec2frac(dec: number, loop_last?: number | undefined, max_den?: number | undefined, max_iter?: number | undefined): Readonly\u003c{\n    a: number;\n    b: number;\n    c: number;\n    i: number;\n    r: string;\n}\u003e\ndec2frac(0.12, 2); //=\u003e { a:0, b:4, c:33, i:0, r:\"precision\" } → 0+4/33 → 0.121212121212...\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-padNum\"\u003e\u003ccode\u003epadNum\u003c/code\u003e\u003c/summary\u003e\n\nconvert number to string with padding \\\nformat: `[sign] [padded start ' '] [.] [padded end '0'] [e ~]`\n\n```typescript\nfunction padNum(n: number | string, first?: number | undefined, last?: number | undefined): string\npadNum(\"1.23e2\", 3, 5); //=\u003e \"+  1.23000e2\"\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-euclideanModulo\"\u003e\u003ccode\u003eeuclideanModulo\u003c/code\u003e\u003c/summary\u003e\n\ncalculates the modulo of two whole numbers (euclidean division)\n\n$$\\large a-\\left(\\lvert b\\rvert\\cdot\\left\\lfloor\\dfrac{a}{\\lvert b\\rvert}\\right\\rfloor\\right)$$\n\n```typescript\nfunction euclideanModulo(a: number, b: number): number\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-randomRange\"\u003e\u003ccode\u003erandomRange\u003c/code\u003e\u003c/summary\u003e\n\ngenarates a random number within given range (inclusive)\n\n_gets a random number via `Math.random()` and assumes that this number is in range [0 to (1 - `Number.EPSILON`)] (inclusive)_\n\n```typescript\nfunction randomRange(min: number, max: number): number\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-randomRangeInt\"\u003e\u003ccode\u003erandomRangeInt\u003c/code\u003e\u003c/summary\u003e\n\ngenarates a random integer within given range (inclusive)\n\n```typescript\nfunction randomRangeInt(min: number, max: number): number\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-divisionWithRest\"\u003e\u003ccode\u003edivisionWithRest\u003c/code\u003e\u003c/summary\u003e\n\ndivision with two unsigned numbers\n\n$$\\large\\dfrac{A}{B}=Q+\\dfrac{R}{B}$$\n\n```typescript\nfunction divisionWithRest(A: number, B: number): readonly [number, number]\ndivisionWithRest(5, 3); //=\u003e [1, 2] → 1+2/3\n```\n\nalso see [`Math-Js/BigIntType.js : #calcDivRest`](https://github.com/MAZ01001/Math-Js/blob/ca71710d50a5fa57e5cb76410cc33df8c1e688d4/BigIntType.js#L1880 \"Permalink to #calcDivRest method in Math-Js/BigIntType.js\") for a solution with arbitrary-length-integers\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-randomBools\"\u003e\u003ccode\u003erandomBools\u003c/code\u003e\u003c/summary\u003e\n\ngenerate a set amount of random booleans \\\n_generator function_\n\n```typescript\nfunction randomBools(amount?: number | undefined): Generator\u003cboolean, any, unknown\u003e\nfor(const rng of randomBools(3))console.log(\"%O\",rng);\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-rangeGenerator\"\u003e\u003ccode\u003erangeGenerator\u003c/code\u003e\u003c/summary\u003e\n\ncreates a generator for given range - iterable \\\n_use `Array.from()` to create a normal `number[]` array_\n\n```typescript\nfunction rangeGenerator(start: number, end: number, step?: number | undefined, overflow?: boolean | undefined): Generator\u003cnumber, void, unknown\u003e\nfor(const odd of rangeGenerator(1, 100, 2))console.log(odd); //~ 1 3 5 .. 97 99\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-rng32bit\"\u003e\u003ccode\u003erng32bit\u003c/code\u003e\u003c/summary\u003e\n\nget a function to get random numbers like Math.random but from a given seed \\\n_uses `MurmurHash3` for seeding and `sfc32` for generating 32bit values_\n\n```typescript\nfunction rng32bit(seed?: string | undefined): () =\u003e number\nrng32bit(\"seed\")();            //=\u003e 3595049765 [0 to 0xFFFFFFFF inclusive]\nrng32bit(\"seed\")()/0xFFFFFFFF; //=\u003e 0.8370377509475307 [0.0 to 1.0 inclusive]\nrng32bit(\"seed\")()/0x100000000;//=\u003e 0.8370377507526428 [0.0 inclusive to 1.0 exclusive]\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-valueNoise\"\u003e\u003ccode\u003evalueNoise\u003c/code\u003e\u003c/summary\u003e\n\ncalculates value noise for given coordinates \\\nuses quintic interpolation for mixing numbers, and a quick (non-cryptographic) hash function to get random noise from coordinates \\\n_the output is allways the same for the same input_\n\n```typescript\nfunction valueNoise(x: number, y: number): number\n```\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cb\u003eExample render\u003c/b\u003e\u003c/summary\u003e\n\nI used the following code to render the background on the [preview of my r/place overlay script](https://maz01001.github.io/rPlaceOverlays/preview \"Open rPlaceOverlays preview page online\")\n\n```javascript\nconst size = Object.freeze([1920, 1080]),\n    exampleNoise = new ImageData(...size, {colorSpace: \"srgb\"});\nfor(let x = 0, y = 0; y \u003c size[1] \u0026\u0026 x \u003c size[0]; ++x \u003e= size[0] ? (x = 0, y++) : 0){\n    const pixel = valueNoise(x * 0.008, y * 0.008) * 127\n        + valueNoise(x * 0.016, y * 0.016) * 63.5\n        + valueNoise(x * 0.032, y * 0.032) * 31.75\n        + valueNoise(x * 0.064, y * 0.064) * 15.875\n        + valueNoise(x * 0.128, y * 0.128) * 7.9375;\n        //// + valueNoise(x * 0.256, y * 0.256) * 3.96875\n        //// + valueNoise(x * 0.512, y * 0.512) * 1.984375;\n    exampleNoise.data.set([pixel, pixel, pixel, 0xFF], (y * size[0] + x) * 4);\n}\ndocument.body.style.backgroundImage = (() =\u003e {\n    \"use strict\";\n    const canvas = document.createElement(\"canvas\");\n    canvas.width = size[0];\n    canvas.height = size[1];\n    canvas.getContext(\"2d\")?.putImageData(exampleNoise, 0, 0);\n    return `url(${ canvas.toDataURL(\"image/png\") })`;\n})();\n```\n\n\u003c/details\u003e\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-factorial\"\u003e\u003ccode\u003efactorial\u003c/code\u003e\u003c/summary\u003e\n\ncalculates the factorial of a non-zero positive integer\n\nmust be either `number` in range `[0..18]` or `bigint`\n\n```typescript\ntype int = number | bigint\nfunction factorial(n: int): int\n```\n\n```javascript\n// number of possible shuffles of a deck of cards\nfactorial(52n);//=\u003e 80658175170943878571660636856403766975289505440883277824000000000000n (~ 8e+67)\n// highest possible with `number` type\nfactorial(18); //=\u003e   6402373705728000\nfactorial(19n);//=\u003e 121645100408832000n\n```\n\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-isPrime\"\u003e\u003ccode\u003eisPrime\u003c/code\u003e\u003c/summary\u003e\n\ncalculates if a given number (in safe integer range: `]-2↑53,2↑53[`) is prime\n\n```typescript\nfunction isPrime(x: number): boolean\n```\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cb\u003ePerformance test\u003c/b\u003e\u003c/summary\u003e\n\n\u003e node.js `v16.13.1` on intel `i7-10700K`\n\n```javascript\nconst t=[\n    performance.now(),isPrime(31),              //=\u003e   0.0472 ms : Prime (warmup)\n    performance.now(),isPrime(31),              //=\u003e   0.0024 ms : Prime\n    performance.now(),isPrime(331),             //=\u003e   0.0014 ms : Prime\n    performance.now(),isPrime(3331),            //=\u003e   0.0013 ms : Prime\n    performance.now(),isPrime(33331),           //=\u003e   0.0050 ms : Prime\n    performance.now(),isPrime(333331),          //=\u003e   0.0089 ms : Prime\n    performance.now(),isPrime(3333331),         //=\u003e   0.0089 ms : Prime\n    performance.now(),isPrime(33333331),        //=\u003e   0.0248 ms : Prime\n    //~ https://oeis.org/A123568 ↑\n    performance.now(),isPrime(6779164939),      //=\u003e   2.4889 ms : Prime\n    performance.now(),isPrime(2**52-1),         //=\u003e   1.3814 ms : -----\n    performance.now(),isPrime(2**52-47),        //=\u003e 118.1830 ms : Prime\n    performance.now(),isPrime(2**53-3155490991),//=\u003e 165.7968 ms : ----- (largest safe prime**2)\n    performance.now(),isPrime(2**53-145),       //=\u003e 165.4307 ms : Prime (2nd largest safe prime)\n    performance.now(),isPrime(2**53-111),       //=\u003e 166.0785 ms : Prime (largest safe prime)\n    performance.now(),isPrime(2**53-94),        //=\u003e   0.0073 ms : ----- (largest safe 2*prime)\n    performance.now(),isPrime(2**53-1),         //=\u003e   0.0123 ms : -----\n    performance.now()\n];\n//@ts-ignore t has an even number of entries where every even element is type `number` and every odd `boolean` (impossible to type-doc and/or detect by linter)\nfor(let i=0;i+1\u003ct.length;i+=2)console.log((t[i+2]-t[i]).toFixed(4).padStart(9),\"ms :\",t[i+1]?\"Prime\":\"-----\");\n```\n\n\u003c/details\u003e\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-lastPrime\"\u003e\u003ccode\u003elastPrime\u003c/code\u003e\u003c/summary\u003e\n\ncalculates the next prime number smaller than the given number (in safe integer range: `]-2↑53,2↑53[`)\n\n`undefined` for numbers `2` and smaller that have no previous prime number\n\n```typescript\nfunction lastPrime(x: number): number|undefined\n```\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cb\u003ePerformance test\u003c/b\u003e\u003c/summary\u003e\n\n\u003e node.js `v16.13.1` on intel `i7-10700K`\n\n```javascript\nconst t=[\n    performance.now(),lastPrime(2),        //=\u003e   0.0454 ms :        undefined (warmup)\n    performance.now(),lastPrime(2),        //=\u003e   0.0019 ms :        undefined\n    performance.now(),lastPrime(8),        //=\u003e   0.0018 ms :                7\n    performance.now(),lastPrime(32),       //=\u003e   0.0014 ms :               31\n    performance.now(),lastPrime(64),       //=\u003e   0.0010 ms :               61\n    performance.now(),lastPrime(1024),     //=\u003e   0.0012 ms :             1021\n    performance.now(),lastPrime(2**20),    //=\u003e   0.0083 ms :          1048573\n    performance.now(),lastPrime(2**30),    //=\u003e   0.2444 ms :       1073741789\n    performance.now(),lastPrime(2**40),    //=\u003e   7.2193 ms :    1099511627689\n    performance.now(),lastPrime(2**50),    //=\u003e  63.1086 ms : 1125899906842597\n    performance.now(),lastPrime(2**53-145),//=\u003e 337.8073 ms : 9007199254740761 (2nd largest safe prime)\n    performance.now(),lastPrime(2**53-111),//=\u003e 173.6542 ms : 9007199254740847 (largest safe prime)\n    performance.now(),lastPrime(2**53-1),  //=\u003e 195.3127 ms : 9007199254740881 (largest safe integer)\n    performance.now()\n];\n//@ts-ignore t has an even number of entries where every even element is type `number` and every odd `boolean` (impossible to type-doc and/or detect by linter)\nfor(let i=0;i+1\u003ct.length;i+=2)console.log((t[i+2]-t[i]).toFixed(4).padStart(9),\"ms :\",String(t[i+1]).padStart(16));\n```\n\n\u003c/details\u003e\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-nextPrime\"\u003e\u003ccode\u003enextPrime\u003c/code\u003e\u003c/summary\u003e\n\ncalculates the next prime number larger than the given number (in safe integer range: `]-2↑53,2↑53[`)\n\n`undefined` when the next prime number is not a safe integer (`\u003e=2↑53`)\n\n```typescript\nfunction nextPrime(x: number): number|undefined\n```\n\n```javascript\n// generate all primes in range [10..100] (via iterator/generator function)\nconsole.log(...(function*(s,e){for(let p=nextPrime(s-1)??NaN;p\u003c=e;p=nextPrime(p)??NaN)yield p;})(10,100));\n//=\u003e 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97\n```\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cb\u003ePerformance test\u003c/b\u003e\u003c/summary\u003e\n\n\u003e node.js `v16.13.1` on intel `i7-10700K`\n\n```javascript\nconst t=[\n    performance.now(),nextPrime(2),        //=\u003e   0.0501 ms :                3 (warmup)\n    performance.now(),nextPrime(2),        //=\u003e   0.0019 ms :                3\n    performance.now(),nextPrime(8),        //=\u003e   0.0022 ms :               11\n    performance.now(),nextPrime(32),       //=\u003e   0.0017 ms :               37\n    performance.now(),nextPrime(64),       //=\u003e   0.0012 ms :               67\n    performance.now(),nextPrime(1024),     //=\u003e   0.0018 ms :             1031\n    performance.now(),nextPrime(2**20),    //=\u003e   0.0097 ms :          1048583\n    performance.now(),nextPrime(2**30),    //=\u003e   0.2133 ms :       1073741827\n    performance.now(),nextPrime(2**40),    //=\u003e   4.2761 ms :    1099511627791\n    performance.now(),nextPrime(2**50),    //=\u003e  78.6495 ms : 1125899906842679\n    performance.now(),nextPrime(2**53-145),//=\u003e 174.2993 ms : 9007199254740881 (2nd largest safe prime)\n    performance.now(),nextPrime(2**53-111),//=\u003e  22.4187 ms :        undefined (largest safe prime)\n    performance.now(),nextPrime(2**53-1),  //=\u003e   0.0056 ms :        undefined (largest safe integer)\n    performance.now()\n];\n//@ts-ignore t has an even number of entries where every even element is type `number` and every odd `boolean` (impossible to type-doc and/or detect by linter)\nfor(let i=0;i+1\u003ct.length;i+=2)console.log((t[i+2]-t[i]).toFixed(4).padStart(9),\"ms :\",String(t[i+1]).padStart(16));\n```\n\n\u003c/details\u003e\n\u003c/details\u003e\n\n\u003cdetails closed\u003e\u003csummary id=\"functionsjs-factorize\"\u003e\u003ccode\u003efactorize\u003c/code\u003e\u003c/summary\u003e\n\ncalculates the prime decomposition of the given safe integer (`]-2↑53..2↑53[`)\n\nprime factors are in ascending order and the list is empty for numbers below `2` (no prime factors)\n\n```typescript\nfunction factorize(n: number): number[]\n```\n\n\u003cdetails open\u003e\u003csummary\u003e\u003cb\u003ePerformance test\u003c/b\u003e\u003c/summary\u003e\n\n\u003e node.js `v16.13.1` on intel `i7-10700K`\n\n```javascript\nconst t=[\n    performance.now(),factorize(4),               //=\u003e   0.0494 ms : 2 2 (warmup)\n    performance.now(),factorize(4),               //=\u003e   0.0022 ms : 2 2\n    performance.now(),factorize(108),             //=\u003e   0.0014 ms : 2 2 3 3 3\n    performance.now(),factorize(337500),          //=\u003e   0.0022 ms : 2 2 3 3 3 5 5 5 5 5\n    performance.now(),factorize(277945762500),    //=\u003e   0.0049 ms : 2 2 3 3 3 5 5 5 5 5 7 7 7 7 7 7 7\n    //~ https://oeis.org/A076265 ↑\n    performance.now(),factorize(33332),           //=\u003e   0.0079 ms : 2 2 13 641\n    performance.now(),factorize(33223575732),     //=\u003e   0.0279 ms : 2 2 3 599 1531 3019\n    performance.now(),factorize(277945762499),    //=\u003e   3.5837 ms : 41 6779164939\n    performance.now(),factorize(2**53-3155490991),//=\u003e 175.6862 ms : 94906249 94906249  (largest safe prime**2)\n    performance.now(),factorize(2**53-111),       //=\u003e 174.6259 ms : 9007199254740881   (largest safe prime)\n    performance.now(),factorize(2**53-94),        //=\u003e 121.8000 ms : 2 4503599627370449 (largest safe 2*prime)\n    performance.now()\n];\n//@ts-ignore t has an even number of entries where every even element is type `number` and every odd `number[]` (impossible to type-doc and/or detect by linter)\nfor(let i=0;i+1\u003ct.length;i+=2)console.log((t[i+2]-t[i]).toFixed(4).padStart(9),\"ms :\",...t[i+1]);\n```\n\n\u003c/details\u003e\n\u003c/details\u003e\n\nScroll [UP](#functionsjs \"Scroll to start of section: functions.js\")\n    | [TOP](#math-in-javascript \"Scroll to top of document: Math in JavaScript\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaz01001%2Fmath-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaz01001%2Fmath-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaz01001%2Fmath-js/lists"}