{"name":"frac","version":"1.0.6","author":{"name":"SheetJS"},"description":"Rational approximation with bounded denominator","keywords":["math","fraction","rational","approximation"],"main":"frac.js","dependencies":{"voc":""},"devDependencies":{"mocha":""},"repository":{"type":"git","url":"git://github.com/SheetJS/frac.git"},"scripts":{"test":"make test"},"config":{"blanket":{"pattern":"frac.js"}},"homepage":"http://oss.sheetjs.com/frac","bugs":{"url":"https://github.com/SheetJS/frac/issues"},"license":"Apache-2.0","engines":{"node":">=0.8"},"gitHead":"395ea31e951ac1863484fb4df34f1f0469cd0ea3","_id":"frac@1.0.6","_shasum":"9a0dfc23956852a8b320623bebcf1be9ea048229","_from":".","_npmVersion":"4.5.0","_nodeVersion":"7.9.0","_npmUser":{"name":"sheetjs","email":"dev@sheetjs.com"},"dist":{"shasum":"9a0dfc23956852a8b320623bebcf1be9ea048229","tarball":"http://registry-npm.ywwl.com/frac/download/frac-1.0.6.tgz","integrity":"sha512-RXTHy3vhoqGKWLkk88tlD0n4d+lFyl5Oa1t1DsyHpR7DkXklWnPwnKhdCM+3kDR5fQuxJ3pr6dZ3yuG1YWGdQQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCn7AWvf7GpKV2W7SPpeTklFccuXMx+VntdoU5dDUrmJgIhAKk2gqvaKSSJ0+rH43D22C5shRaoEaqGadxT7jo5Mqw9"}],"size":6683,"noattachment":false,"key":"/frac/-/frac-1.0.6.tgz"},"maintainers":[{"name":"sheetjs","email":"dev@sheetjs.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/frac-1.0.6.tgz_1493487266407_0.5516871849540621"},"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":1493487267059,"_cnpm_publish_time":1493487267059,"dist-tags":{"latest":"1.1.2"}}