{"name":"frac","version":"1.1.1","author":{"name":"SheetJS"},"description":"Rational approximation with bounded denominator","keywords":["math","fraction","rational","approximation"],"main":"./frac","types":"types","dependencies":{"voc":"~1.0.0"},"devDependencies":{"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"},"gitHead":"9ef2c47f0408a538aa263ef9ff3352197a814257","_id":"frac@1.1.1","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"sheetjs","email":"dev@sheetjs.com"},"dist":{"integrity":"sha512-UKV4N/r4PQQgdjrmiI5XOv+dII8OgwXQaEIUNj/vH1KtvaTwIBRwVobAWwEKPK7HLJmSwru/1a1A88TB/DtxZg==","shasum":"5f7f5c2ae029167d90153eea4b7dd2958d43d1f5","tarball":"http://registry-npm.ywwl.com/frac/download/frac-1.1.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIArlXh16IwyaMLBfKrFLlGpEciX64WVd82lVvluD7a2lAiEAhZAxPZVBvhGL7lAeMj6u01dkfSdn056HkDQSQAX+7Ks="}],"size":7166,"noattachment":false,"key":"/frac/-/frac-1.1.1.tgz"},"maintainers":[{"name":"sheetjs","email":"dev@sheetjs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/frac-1.1.1.tgz_1516338799659_0.6169088410679251"},"directories":{},"readme":"# frac\n\nRational approximation to a floating point number with bounded denominator.\n\nUses the [Mediant Method](https://en.wikipedia.org/wiki/Mediant_method).\n\nThis module also provides an implementation of the continued fraction method as\ndescribed by Aberth in \"A method for exact computation with rational numbers\".\nThe algorithm is used in <a href=\"http://sheetjs.com\">SheetJS Libraries</a> to\nreplicate fraction formats.\n\n## Installation\n\n### JS\n\nWith [`npm`](https://www.npmjs.org/package/frac):\n\n```bash\n$ npm install frac\n```\n\nIn the browser:\n\n```html\n<script src=\"frac.js\"></script>\n```\n\nThe script will manipulate `module.exports` if available .  This is not always\ndesirable.  To prevent the behavior, define `DO_NOT_EXPORT_FRAC`\n\n### Python\n\nFrom [`PyPI`](https://pypi.python.org/pypi/frac):\n\n```bash\n$ pip install frac\n```\n\n## Usage\n\nIn all cases, the relevant function takes 3 arguments:\n\n - `x` the number we wish to approximate\n - `D` the maximum denominator\n - `mixed` if true, return a mixed fraction; if false, improper\n\nThe return value is an array of the form `[quot, num, den]` where `quot==0`\nfor improper fractions.  `quot <= x` for mixed fractions, which may lead to some\nunexpected results when rendering negative numbers.\n\n### JS\n\nThe exported `frac` function implements the Mediant method.\n\n`frac.cont` implements the Aberth algorithm\n\nFor example:\n\n```js\n> // var frac = require('frac'); // uncomment this line if in node\n> frac(1.3, 9);              // [  0,  9, 7 ] //  1.3 ~       9/7\n> frac(1.3, 9, true);        // [  1,  2, 7 ] //  1.3 ~  1 +  2/7\n> frac(-1.3, 9);             // [  0, -9, 7 ] // -1.3 ~      -9/7\n> frac(-1.3, 9, true);       // [ -2,  5, 7 ] // -1.3 ~ -2 +  5/7\n\n> frac.cont(1.3, 9);         // [  0,  4, 3 ] //  1.3 ~       4/3\n> frac.cont(1.3, 9, true);   // [  1,  1, 3 ] //  1.3 ~  1 +  1/3\n> frac.cont(-1.3, 9);        // [  0, -4, 3 ] // -1.3 ~      -4/3\n> frac.cont(-1.3, 9, true);  // [ -2,  2, 3 ] // -1.3 ~ -2 +  2/3\n```\n\n\n### Python\n\n`frac.med` implements Mediant method.\n\n`frac.cont` implements Aberth algorithm.\n\nFor example:\n\n```py\n>>> import frac\n>>> frac.med(1.3, 9)         ## [  0,  9, 7 ] ##  1.3 ~       9/7\n>>> frac.med(1.3, 9, True)   ## [  1,  2, 7 ] ##  1.3 ~  1 +  2/7\n>>> frac.med(-1.3, 9)        ## [  0, -9, 7 ] ## -1.3 ~      -9/7\n>>> frac.med(-1.3, 9, True)  ## [ -2,  5, 7 ] ## -1.3 ~ -2 +  5/7\n\n>>> frac.cont(1.3, 9)        ## [  0,  4, 3 ] ##  1.3 ~       4/3\n>>> frac.cont(1.3, 9, True)  ## [  1,  1, 3 ] ##  1.3 ~  1 +  1/3\n>>> frac.cont(-1.3, 9)       ## [  0, -4, 3 ] ## -1.3 ~      -4/3\n>>> frac.cont(-1.3, 9, True) ## [ -2,  2, 3 ] ## -1.3 ~ -2 +  2/3\n```\n\n## Testing\n\nThe test TSV baselines in the `test_files` directory have four columns:\n\n- Column A contains the raw values\n- Column B format \"Up to one digit (1/4)\" (`denominator = 9`)\n- Column C format \"Up to two digits (21/25)\" (`denominator = 99`)\n- Column D format \"Up to three digits (312/943)\" (`denominator = 999`)\n\n`make test` will run the node-based tests.\n\n`make pytest` will run the python tests against the system Python version.\n\n`make pypytest` will run the python tests against `pypy` if installed\n\n## License\n\nPlease consult the attached LICENSE file for details.  All rights not explicitly\ngranted by the Apache 2.0 License are reserved by the Original Author.\n\n## Badges\n\n[![Build Status](https://saucelabs.com/browser-matrix/frac.svg)](https://saucelabs.com/u/frac)\n\n[![Build Status](https://travis-ci.org/SheetJS/frac.svg?branch=master)](https://travis-ci.org/SheetJS/frac)\n\n[![Coverage Status](http://img.shields.io/coveralls/SheetJS/frac/master.svg)](https://coveralls.io/r/SheetJS/frac?branch=master)\n\n[![NPM Downloads](https://img.shields.io/npm/dt/frac.svg)](https://npmjs.org/package/frac)\n\n[![Dependencies Status](https://david-dm.org/sheetjs/frac/status.svg)](https://david-dm.org/sheetjs/frac)\n\n[![ghit.me](https://ghit.me/badge.svg?repo=sheetjs/js-xlsx)](https://ghit.me/repo/sheetjs/js-xlsx)\n\n[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/frac?pixel)](https://github.com/SheetJS/frac)\n","publish_time":1516338799743,"_cnpm_publish_time":1516338799743,"dist-tags":{"latest":"1.1.2"}}