Initial commit
This commit is contained in:
13
node_modules/frac/LICENSE
generated
vendored
Normal file
13
node_modules/frac/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
Copyright (C) 2012-present SheetJS
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
128
node_modules/frac/README.md
generated
vendored
Normal file
128
node_modules/frac/README.md
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
# frac
|
||||
|
||||
Rational approximation to a floating point number with bounded denominator.
|
||||
|
||||
Uses the [Mediant Method](https://en.wikipedia.org/wiki/Mediant_method).
|
||||
|
||||
This module also provides an implementation of the continued fraction method as
|
||||
described by Aberth in "A method for exact computation with rational numbers".
|
||||
The algorithm is used in <a href="http://sheetjs.com">SheetJS Libraries</a> to
|
||||
replicate fraction formats.
|
||||
|
||||
## Installation
|
||||
|
||||
### JS
|
||||
|
||||
With [`npm`](https://www.npmjs.org/package/frac):
|
||||
|
||||
```bash
|
||||
$ npm install frac
|
||||
```
|
||||
|
||||
In the browser:
|
||||
|
||||
```html
|
||||
<script src="frac.js"></script>
|
||||
```
|
||||
|
||||
The script will manipulate `module.exports` if available . This is not always
|
||||
desirable. To prevent the behavior, define `DO_NOT_EXPORT_FRAC`
|
||||
|
||||
### Python
|
||||
|
||||
From [`PyPI`](https://pypi.python.org/pypi/frac):
|
||||
|
||||
```bash
|
||||
$ pip install frac
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
In all cases, the relevant function takes 3 arguments:
|
||||
|
||||
- `x` the number we wish to approximate
|
||||
- `D` the maximum denominator
|
||||
- `mixed` if true, return a mixed fraction; if false, improper
|
||||
|
||||
The return value is an array of the form `[quot, num, den]` where `quot==0`
|
||||
for improper fractions. `quot <= x` for mixed fractions, which may lead to some
|
||||
unexpected results when rendering negative numbers.
|
||||
|
||||
### JS
|
||||
|
||||
The exported `frac` function implements the Mediant method.
|
||||
|
||||
`frac.cont` implements the Aberth algorithm
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
> // var frac = require('frac'); // uncomment this line if in node
|
||||
> frac(1.3, 9); // [ 0, 9, 7 ] // 1.3 ~ 9/7
|
||||
> frac(1.3, 9, true); // [ 1, 2, 7 ] // 1.3 ~ 1 + 2/7
|
||||
> frac(-1.3, 9); // [ 0, -9, 7 ] // -1.3 ~ -9/7
|
||||
> frac(-1.3, 9, true); // [ -2, 5, 7 ] // -1.3 ~ -2 + 5/7
|
||||
|
||||
> frac.cont(1.3, 9); // [ 0, 4, 3 ] // 1.3 ~ 4/3
|
||||
> frac.cont(1.3, 9, true); // [ 1, 1, 3 ] // 1.3 ~ 1 + 1/3
|
||||
> frac.cont(-1.3, 9); // [ 0, -4, 3 ] // -1.3 ~ -4/3
|
||||
> frac.cont(-1.3, 9, true); // [ -2, 2, 3 ] // -1.3 ~ -2 + 2/3
|
||||
```
|
||||
|
||||
|
||||
### Python
|
||||
|
||||
`frac.med` implements Mediant method.
|
||||
|
||||
`frac.cont` implements Aberth algorithm.
|
||||
|
||||
For example:
|
||||
|
||||
```py
|
||||
>>> import frac
|
||||
>>> frac.med(1.3, 9) ## [ 0, 9, 7 ] ## 1.3 ~ 9/7
|
||||
>>> frac.med(1.3, 9, True) ## [ 1, 2, 7 ] ## 1.3 ~ 1 + 2/7
|
||||
>>> frac.med(-1.3, 9) ## [ 0, -9, 7 ] ## -1.3 ~ -9/7
|
||||
>>> frac.med(-1.3, 9, True) ## [ -2, 5, 7 ] ## -1.3 ~ -2 + 5/7
|
||||
|
||||
>>> frac.cont(1.3, 9) ## [ 0, 4, 3 ] ## 1.3 ~ 4/3
|
||||
>>> frac.cont(1.3, 9, True) ## [ 1, 1, 3 ] ## 1.3 ~ 1 + 1/3
|
||||
>>> frac.cont(-1.3, 9) ## [ 0, -4, 3 ] ## -1.3 ~ -4/3
|
||||
>>> frac.cont(-1.3, 9, True) ## [ -2, 2, 3 ] ## -1.3 ~ -2 + 2/3
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
The test TSV baselines in the `test_files` directory have four columns:
|
||||
|
||||
- Column A contains the raw values
|
||||
- Column B format "Up to one digit (1/4)" (`denominator = 9`)
|
||||
- Column C format "Up to two digits (21/25)" (`denominator = 99`)
|
||||
- Column D format "Up to three digits (312/943)" (`denominator = 999`)
|
||||
|
||||
`make test` will run the node-based tests.
|
||||
|
||||
`make pytest` will run the python tests against the system Python version.
|
||||
|
||||
`make pypytest` will run the python tests against `pypy` if installed
|
||||
|
||||
## License
|
||||
|
||||
Please consult the attached LICENSE file for details. All rights not explicitly
|
||||
granted by the Apache 2.0 License are reserved by the Original Author.
|
||||
|
||||
## Badges
|
||||
|
||||
[](https://saucelabs.com/u/frac)
|
||||
|
||||
[](https://travis-ci.org/SheetJS/frac)
|
||||
|
||||
[](https://coveralls.io/r/SheetJS/frac?branch=master)
|
||||
|
||||
[](https://npmjs.org/package/frac)
|
||||
|
||||
[](https://david-dm.org/sheetjs/frac)
|
||||
|
||||
[](https://ghit.me/repo/sheetjs/js-xlsx)
|
||||
|
||||
[](https://github.com/SheetJS/frac)
|
||||
13
node_modules/frac/dist/LICENSE
generated
vendored
Normal file
13
node_modules/frac/dist/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
Copyright (C) 2012-present SheetJS
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
42
node_modules/frac/dist/frac.js
generated
vendored
Normal file
42
node_modules/frac/dist/frac.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/* frac.js (C) 2012-present SheetJS -- http://sheetjs.com */
|
||||
var frac = function frac(x, D, mixed) {
|
||||
var n1 = Math.floor(x), d1 = 1;
|
||||
var n2 = n1+1, d2 = 1;
|
||||
if(x !== n1) while(d1 <= D && d2 <= D) {
|
||||
var m = (n1 + n2) / (d1 + d2);
|
||||
if(x === m) {
|
||||
if(d1 + d2 <= D) { d1+=d2; n1+=n2; d2=D+1; }
|
||||
else if(d1 > d2) d2=D+1;
|
||||
else d1=D+1;
|
||||
break;
|
||||
}
|
||||
else if(x < m) { n2 = n1+n2; d2 = d1+d2; }
|
||||
else { n1 = n1+n2; d1 = d1+d2; }
|
||||
}
|
||||
if(d1 > D) { d1 = d2; n1 = n2; }
|
||||
if(!mixed) return [0, n1, d1];
|
||||
var q = Math.floor(n1/d1);
|
||||
return [q, n1 - q*d1, d1];
|
||||
};
|
||||
frac.cont = function cont(x, D, mixed) {
|
||||
var sgn = x < 0 ? -1 : 1;
|
||||
var B = x * sgn;
|
||||
var P_2 = 0, P_1 = 1, P = 0;
|
||||
var Q_2 = 1, Q_1 = 0, Q = 0;
|
||||
var A = Math.floor(B);
|
||||
while(Q_1 < D) {
|
||||
A = Math.floor(B);
|
||||
P = A * P_1 + P_2;
|
||||
Q = A * Q_1 + Q_2;
|
||||
if((B - A) < 0.00000005) break;
|
||||
B = 1 / (B - A);
|
||||
P_2 = P_1; P_1 = P;
|
||||
Q_2 = Q_1; Q_1 = Q;
|
||||
}
|
||||
if(Q > D) { if(Q_1 > D) { Q = Q_2; P = P_2; } else { Q = Q_1; P = P_1; } }
|
||||
if(!mixed) return [0, sgn * P, Q];
|
||||
var q = Math.floor(sgn * P/Q);
|
||||
return [q, sgn*P - q*Q, Q];
|
||||
};
|
||||
// eslint-disable-next-line no-undef
|
||||
if(typeof module !== 'undefined' && typeof DO_NOT_EXPORT_FRAC === 'undefined') module.exports = frac;
|
||||
2
node_modules/frac/dist/frac.min.js
generated
vendored
Normal file
2
node_modules/frac/dist/frac.min.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/* frac.js (C) 2012-present SheetJS -- http://sheetjs.com */
|
||||
var frac=function frac(x,D,mixed){var n1=Math.floor(x),d1=1;var n2=n1+1,d2=1;if(x!==n1)while(d1<=D&&d2<=D){var m=(n1+n2)/(d1+d2);if(x===m){if(d1+d2<=D){d1+=d2;n1+=n2;d2=D+1}else if(d1>d2)d2=D+1;else d1=D+1;break}else if(x<m){n2=n1+n2;d2=d1+d2}else{n1=n1+n2;d1=d1+d2}}if(d1>D){d1=d2;n1=n2}if(!mixed)return[0,n1,d1];var q=Math.floor(n1/d1);return[q,n1-q*d1,d1]};frac.cont=function cont(x,D,mixed){var sgn=x<0?-1:1;var B=x*sgn;var P_2=0,P_1=1,P=0;var Q_2=1,Q_1=0,Q=0;var A=Math.floor(B);while(Q_1<D){A=Math.floor(B);P=A*P_1+P_2;Q=A*Q_1+Q_2;if(B-A<5e-8)break;B=1/(B-A);P_2=P_1;P_1=P;Q_2=Q_1;Q_1=Q}if(Q>D){if(Q_1>D){Q=Q_2;P=P_2}else{Q=Q_1;P=P_1}}if(!mixed)return[0,sgn*P,Q];var q=Math.floor(sgn*P/Q);return[q,sgn*P-q*Q,Q]};if(typeof module!=="undefined"&&typeof DO_NOT_EXPORT_FRAC==="undefined")module.exports=frac;
|
||||
1
node_modules/frac/dist/frac.min.map
generated
vendored
Normal file
1
node_modules/frac/dist/frac.min.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["frac.js"],"names":["frac","x","D","mixed","n1","Math","floor","d1","n2","d2","m","q","cont","sgn","B","P_2","P_1","P","Q_2","Q_1","Q","A","module","DO_NOT_EXPORT_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lB,EAAG,CAAE,GAAGiB,IAAMjB,EAAG,CAAEkB,EAAIF,GAAKD,GAAIF,QAAY,CAAEK,EAAID,GAAKF,GAAID,KAClE,IAAIb,MAAO,OAAQ,EAAGU,IAAMI,EAAGG,EAC/B,IAAIT,GAAIN,KAAKC,MAAMO,IAAMI,EAAEG,EAC3B,QAAQT,EAAGE,IAAII,EAAIN,EAAES,EAAGA,GAG1B,UAAUE,UAAW,mBAAsBC,sBAAuB,YAAaD,OAAOE,QAAUxB","file":"dist/frac.min.js"}
|
||||
42
node_modules/frac/frac.js
generated
vendored
Normal file
42
node_modules/frac/frac.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/* frac.js (C) 2012-present SheetJS -- http://sheetjs.com */
|
||||
var frac = function frac(x, D, mixed) {
|
||||
var n1 = Math.floor(x), d1 = 1;
|
||||
var n2 = n1+1, d2 = 1;
|
||||
if(x !== n1) while(d1 <= D && d2 <= D) {
|
||||
var m = (n1 + n2) / (d1 + d2);
|
||||
if(x === m) {
|
||||
if(d1 + d2 <= D) { d1+=d2; n1+=n2; d2=D+1; }
|
||||
else if(d1 > d2) d2=D+1;
|
||||
else d1=D+1;
|
||||
break;
|
||||
}
|
||||
else if(x < m) { n2 = n1+n2; d2 = d1+d2; }
|
||||
else { n1 = n1+n2; d1 = d1+d2; }
|
||||
}
|
||||
if(d1 > D) { d1 = d2; n1 = n2; }
|
||||
if(!mixed) return [0, n1, d1];
|
||||
var q = Math.floor(n1/d1);
|
||||
return [q, n1 - q*d1, d1];
|
||||
};
|
||||
frac.cont = function cont(x, D, mixed) {
|
||||
var sgn = x < 0 ? -1 : 1;
|
||||
var B = x * sgn;
|
||||
var P_2 = 0, P_1 = 1, P = 0;
|
||||
var Q_2 = 1, Q_1 = 0, Q = 0;
|
||||
var A = Math.floor(B);
|
||||
while(Q_1 < D) {
|
||||
A = Math.floor(B);
|
||||
P = A * P_1 + P_2;
|
||||
Q = A * Q_1 + Q_2;
|
||||
if((B - A) < 0.00000005) break;
|
||||
B = 1 / (B - A);
|
||||
P_2 = P_1; P_1 = P;
|
||||
Q_2 = Q_1; Q_1 = Q;
|
||||
}
|
||||
if(Q > D) { if(Q_1 > D) { Q = Q_2; P = P_2; } else { Q = Q_1; P = P_1; } }
|
||||
if(!mixed) return [0, sgn * P, Q];
|
||||
var q = Math.floor(sgn * P/Q);
|
||||
return [q, sgn*P - q*Q, Q];
|
||||
};
|
||||
// eslint-disable-next-line no-undef
|
||||
if(typeof module !== 'undefined' && typeof DO_NOT_EXPORT_FRAC === 'undefined') module.exports = frac;
|
||||
36
node_modules/frac/package.json
generated
vendored
Normal file
36
node_modules/frac/package.json
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "frac",
|
||||
"version": "1.1.2",
|
||||
"author": "SheetJS",
|
||||
"description": "Rational approximation with bounded denominator",
|
||||
"keywords": [ "math", "fraction", "rational", "approximation" ],
|
||||
"main": "./frac",
|
||||
"types": "types",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"voc": "~1.1.0",
|
||||
"mocha": "~2.5.3",
|
||||
"blanket": "~1.2.3",
|
||||
"codepage": "~1.10.0",
|
||||
"@sheetjs/uglify-js": "~2.7.3",
|
||||
"@types/node": "^8.0.7",
|
||||
"dtslint": "^0.1.2",
|
||||
"typescript": "2.2.0"
|
||||
},
|
||||
"repository": { "type":"git", "url":"git://github.com/SheetJS/frac.git" },
|
||||
"scripts": {
|
||||
"test": "make test",
|
||||
"build": "make",
|
||||
"lint": "make fullint",
|
||||
"dtslint": "dtslint types"
|
||||
},
|
||||
"config": {
|
||||
"blanket": {
|
||||
"pattern": "frac.js"
|
||||
}
|
||||
},
|
||||
"homepage": "http://sheetjs.com/opensource",
|
||||
"bugs": { "url": "https://github.com/SheetJS/frac/issues" },
|
||||
"license": "Apache-2.0",
|
||||
"engines": { "node": ">=0.8" }
|
||||
}
|
||||
9
node_modules/frac/types/index.d.ts
generated
vendored
Normal file
9
node_modules/frac/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/* frac.js (C) 2012-present SheetJS -- http://sheetjs.com */
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export interface Frac$Module {
|
||||
(x: number, D: number, mixed?: boolean): [number, number, number];
|
||||
cont(x: number, D: number, mixed?: boolean): [number, number, number];
|
||||
}
|
||||
export const frac: Frac$Module;
|
||||
export default frac;
|
||||
14
node_modules/frac/types/tsconfig.json
generated
vendored
Normal file
14
node_modules/frac/types/tsconfig.json
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [ "es5" ],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": ".",
|
||||
"paths": { "frac": ["."] },
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
11
node_modules/frac/types/tslint.json
generated
vendored
Normal file
11
node_modules/frac/types/tslint.json
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "dtslint/dtslint.json",
|
||||
"rules": {
|
||||
"whitespace": false,
|
||||
"no-sparse-arrays": false,
|
||||
"only-arrow-functions": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"one-variable-per-declaration": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user