@fav/arith.reduce
Advanced tools
Comparing version 0.1.1 to 0.1.2
28
index.js
@@ -5,2 +5,3 @@ 'use strict'; | ||
var gcd = require('@fav/math.gcd'); | ||
var NMAX = ArithNumber.MAX_SAFE_NUMERATOR / 10; | ||
@@ -16,2 +17,6 @@ function reduce(arithNum) { | ||
if (arithNum.denominator === 1) { | ||
return new ArithNumber(arithNum.numerator, 1, arithNum.exponent); | ||
} | ||
var n = Math.abs(arithNum.numerator); | ||
@@ -25,8 +30,19 @@ var d = arithNum.denominator; | ||
var n10; | ||
while (((n10 = n * 10) <= ArithNumber.MAX_SAFE_NUMERATOR) && | ||
(g = gcd(d, 10)) !== 1) { | ||
n = n10 / g; | ||
d = d / g; | ||
e -= 1; | ||
while (n < NMAX && e > -ArithNumber.MAX_SAFE_EXPONENT) { | ||
var m2 = d % 2, | ||
m5 = d % 5; | ||
if (m2 === 0 && m5 === 0) { | ||
d /= 10; | ||
e--; | ||
} else if (m2 === 0) { | ||
n *= 5; | ||
d /= 2; | ||
e--; | ||
} else if (m5 === 0) { | ||
n *= 2; | ||
d /= 5; | ||
e--; | ||
} else { | ||
break; | ||
} | ||
} | ||
@@ -33,0 +49,0 @@ |
{ | ||
"name": "@fav/arith.reduce", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Reduces a number for accurate arithmetics.", | ||
@@ -13,2 +13,3 @@ "main": "index.js", | ||
"test": "mocha", | ||
"benchmark": "node benchmark/index.js", | ||
"coverage": "nyc --reporter=lcov --reporter=text-summary npm test", | ||
@@ -43,2 +44,4 @@ "coveralls": "nyc --reporter=text-lcov npm test | coveralls", | ||
"devDependencies": { | ||
"benchmark": "^2.1.4", | ||
"benchmark-tester": "^0.2.0", | ||
"browserify": "^16.1.0", | ||
@@ -48,9 +51,11 @@ "browserify-shim": "^3.8.14", | ||
"coveralls": "^3.0.0", | ||
"eslint": "^4.8.0", | ||
"eslint": "^5.8.0", | ||
"lodash": "^4.17.11", | ||
"mocha": "^3.5.3", | ||
"nyc": "^11.2.1", | ||
"nyc": "^13.1.0", | ||
"platform": "^1.3.5", | ||
"uglify-js": "^3.1.3" | ||
}, | ||
"dependencies": { | ||
"@fav/arith.number": "^0.1.3", | ||
"@fav/arith.number": "^0.1.5", | ||
"@fav/math.gcd": "^0.1.0" | ||
@@ -57,0 +62,0 @@ }, |
@@ -58,3 +58,3 @@ # [@fav/arith.reduce][repo-url] [![NPM][npm-img]][npm-url] [![MIT License][mit-img]][mit-url] [![Build Status][travis-img]][travis-url] [![Build Status][appveyor-img]][appveyor-url] [![Coverage status][coverage-img]][coverage-url] | ||
This function reducesto get a possibly minimal *denominator* with decreasing *exponent*. For example, `(9 / 6)` is reduced to not `(3 / 2)` but `(15 / 1) * 10^1`. | ||
This function reduces to get a possibly minimal *denominator* with decreasing *exponent*. For example, `(9 / 6)` is reduced to not `(3 / 2)` but `(15 / 1) * 10^-1`. | ||
@@ -88,4 +88,12 @@ #### Parameters: | ||
### Node.js (4〜) | ||
### Node.js (11〜) | ||
| Platform | 11 | | ||
|:---------:|:------:| | ||
| macOS |◯| | ||
| Windows10 |◯| | ||
| Linux |◯| | ||
### Node.js (4〜10) | ||
| Platform | 4 | 5 | 6 | 7 | 8 | 9 | 10 | | ||
@@ -130,3 +138,3 @@ |:---------:|:------:|:------:|:------:|:------:|:------:|:------:|:------:| | ||
[repo-url]: https://github.com/sttk/fav-arith.reduce/ | ||
[npm-img]: https://img.shields.io/badge/npm-v0.1.1-blue.svg | ||
[npm-img]: https://img.shields.io/badge/npm-v0.1.2-blue.svg | ||
[npm-url]: https://www.npmjs.com/package/@fav/arith.reduce | ||
@@ -133,0 +141,0 @@ [mit-img]: https://img.shields.io/badge/license-MIT-green.svg |
@@ -7,2 +7,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g=(g.fav||(g.fav = {}));g=(g.arith||(g.arith = {}));g.reduce = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
var gcd = require('@fav/math.gcd'); | ||
var NMAX = ArithNumber.MAX_SAFE_NUMERATOR / 10; | ||
@@ -18,2 +19,6 @@ function reduce(arithNum) { | ||
if (arithNum.denominator === 1) { | ||
return new ArithNumber(arithNum.numerator, 1, arithNum.exponent); | ||
} | ||
var n = Math.abs(arithNum.numerator); | ||
@@ -27,8 +32,19 @@ var d = arithNum.denominator; | ||
var n10; | ||
while (((n10 = n * 10) <= ArithNumber.MAX_SAFE_NUMERATOR) && | ||
(g = gcd(d, 10)) !== 1) { | ||
n = n10 / g; | ||
d = d / g; | ||
e -= 1; | ||
while (n < NMAX && e > -ArithNumber.MAX_SAFE_EXPONENT) { | ||
var m2 = d % 2, | ||
m5 = d % 5; | ||
if (m2 === 0 && m5 === 0) { | ||
d /= 10; | ||
e--; | ||
} else if (m2 === 0) { | ||
n *= 5; | ||
d /= 2; | ||
e--; | ||
} else if (m5 === 0) { | ||
n *= 2; | ||
d /= 5; | ||
e--; | ||
} else { | ||
break; | ||
} | ||
} | ||
@@ -35,0 +51,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;(n=(n=(n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).fav||(n.fav={})).arith||(n.arith={})).reduce=e()}}(function(){return function f(i,u,a){function d(n,e){if(!u[n]){if(!i[n]){var r="function"==typeof require&&require;if(!e&&r)return r(n,!0);if(c)return c(n,!0);var t=new Error("Cannot find module '"+n+"'");throw t.code="MODULE_NOT_FOUND",t}var o=u[n]={exports:{}};i[n][0].call(o.exports,function(e){return d(i[n][1][e]||e)},o,o.exports,f,i,u,a)}return u[n].exports}for(var c="function"==typeof require&&require,e=0;e<a.length;e++)d(a[e]);return d}({1:[function(r,t,e){(function(e){"use strict";var i="undefined"!=typeof window?window.fav.arith.number:void 0!==e?e.fav.arith.number:null,u=r("@fav/math.gcd");function n(e){if(!e.isAccurate())return new i(NaN,NaN,NaN);if(0===e.numerator)return new i(0,1,0);var n,r=Math.abs(e.numerator),t=e.denominator,o=e.exponent,f=u(r,t);for(r/=f,t/=f;(n=10*r)<=i.MAX_SAFE_NUMERATOR&&1!==(f=u(t,10));)r=n/f,t/=f,o-=1;return e.numerator<0&&(r=-r),new i(r,t,o)}i.prototype.reduce=function(){return n(this)},t.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"@fav/math.gcd":2}],2:[function(e,n,r){"use strict";n.exports=function(e,n){if(!e||!n)return 1;for(var r;0!==n;)r=e%n,e=n,n=r;return Math.abs(e)}},{}]},{},[1])(1)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;(n=(n=(n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).fav||(n.fav={})).arith||(n.arith={})).reduce=e()}}(function(){return function f(i,u,a){function d(n,e){if(!u[n]){if(!i[n]){var r="function"==typeof require&&require;if(!e&&r)return r(n,!0);if(c)return c(n,!0);var t=new Error("Cannot find module '"+n+"'");throw t.code="MODULE_NOT_FOUND",t}var o=u[n]={exports:{}};i[n][0].call(o.exports,function(e){return d(i[n][1][e]||e)},o,o.exports,f,i,u,a)}return u[n].exports}for(var c="function"==typeof require&&require,e=0;e<a.length;e++)d(a[e]);return d}({1:[function(r,t,e){(function(e){"use strict";var u="undefined"!=typeof window?window.fav.arith.number:void 0!==e?e.fav.arith.number:null,a=r("@fav/math.gcd"),d=u.MAX_SAFE_NUMERATOR/10;function n(e){if(!e.isAccurate())return new u(NaN,NaN,NaN);if(0===e.numerator)return new u(0,1,0);if(1===e.denominator)return new u(e.numerator,1,e.exponent);var n=Math.abs(e.numerator),r=e.denominator,t=e.exponent,o=a(n,r);for(n/=o,r/=o;n<d&&t>-u.MAX_SAFE_EXPONENT;){var f=r%2,i=r%5;if(0===f&&0===i)r/=10,t--;else if(0===f)n*=5,r/=2,t--;else{if(0!==i)break;n*=2,r/=5,t--}}return e.numerator<0&&(n=-n),new u(n,r,t)}u.prototype.reduce=function(){return n(this)},t.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"@fav/math.gcd":2}],2:[function(e,n,r){"use strict";n.exports=function(e,n){if(!e||!n)return 1;for(var r;0!==n;)r=e%n,e=n,n=r;return Math.abs(e)}},{}]},{},[1])(1)}); | ||
//# sourceMappingURL=fav.arith.reduce.min.js.map |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
16489
124
146
12
1
Updated@fav/arith.number@^0.1.5