├── .editorconfig ├── .gitattributes ├── .github ├── security.md └── workflows │ └── main.yml ├── .gitignore ├── .jshintrc ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 14 14 | - 12 15 | - 10 16 | - 8 17 | - 6 18 | - 4 19 | - 0.12 20 | - 0.10 21 | steps: 22 | - uses: actions/checkout@v2 23 | - uses: actions/setup-node@v1 24 | with: 25 | node-version: ${{ matrix.node-version }} 26 | - run: npm install 27 | - run: npm test 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "curly": true, 6 | "immed": true, 7 | "newcap": true, 8 | "noarg": true, 9 | "undef": true, 10 | "unused": "vars", 11 | "strict": true 12 | } 13 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = Math.imul || function (a, b) { 3 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul 4 | var ah = (a >>> 16) & 0xffff; 5 | var al = a & 0xffff; 6 | var bh = (b >>> 16) & 0xffff; 7 | var bl = b & 0xffff; 8 | return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0) | 0); 9 | }; 10 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "imul", 3 | "version": "1.0.1", 4 | "description": "ES2015 Math.imul() ponyfill", 5 | "license": "MIT", 6 | "repository": "sindresorhus/imul", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "engines": { 13 | "node": ">=0.10.0" 14 | }, 15 | "scripts": { 16 | "test": "ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "es2015", 23 | "ponyfill", 24 | "polyfill", 25 | "shim", 26 | "number", 27 | "math", 28 | "imul", 29 | "multiplication" 30 | ], 31 | "devDependencies": { 32 | "ava": "*" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | Deprecated as this is now natively available in all modern browsers and Node.js versions. 2 | 3 | --- 4 | 5 | # imul 6 | 7 | > ES2015 [`Math.imul()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul) [ponyfill](https://ponyfill.com) 8 | 9 | 10 | ## Install 11 | 12 | ``` 13 | $ npm install --save imul 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ```js 20 | var imul = require('imul'); 21 | 22 | imul(2, 4); 23 | //=> 8 24 | ``` 25 | 26 | 27 | ## License 28 | 29 | MIT © [Sindre Sorhus](http://sindresorhus.com) 30 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | 3 | Math.imul = undefined; 4 | const m = require('./'); 5 | 6 | test(t => { 7 | t.is(m(5, -0), 0); 8 | t.is(m(0.2, 7), 0); 9 | t.is(m(7, 0.9), 0); 10 | t.is(m(0.4, 7), 0); 11 | t.is(m(-0, 7), 0); 12 | t.is(m(8, 0.1), 0); 13 | t.is(m(-1, 8), -8); 14 | t.is(m(-2, -2), 4); 15 | t.is(m(7, 1.9), 7); 16 | t.is(m(2, 4), 8); 17 | t.is(m(1.9, 7), 7); 18 | t.is(m(1.1, 7), 7); 19 | t.is(m(7, 1.1), 7); 20 | t.is(m(0xfffffffe, 5), -10); 21 | t.is(m(0xffffffff, 5), -5); 22 | }); 23 | --------------------------------------------------------------------------------