{"name":"frac","version":"0.2.1","author":{"name":"SheetJS"},"description":"Rational approximation with bounded denominator","keywords":["math","fraction","rational","approximation"],"main":"./frac.js","dependencies":{},"devDependencies":{"mocha":""},"repository":{"type":"git","url":"git://github.com/SheetJS/frac.git"},"scripts":{"test":"make test"},"bugs":{"url":"https://github.com/SheetJS/frac/issues"},"engines":{"node":">=0.8"},"homepage":"https://github.com/SheetJS/frac","_id":"frac@0.2.1","dist":{"shasum":"27470b5850455b0b16b25522fc4dab464dc0ea18","tarball":"http://registry-npm.ywwl.com/frac/download/frac-0.2.1.tgz","integrity":"sha512-ka7Z5755RrlB6oaDhK1LEBoIvoo8mVvJH7faLvpeQRIP3zKGJFd8oDdpn08I1vimwEe3nM9ZcZgoEWhcqWWJ9w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD1U5LeIvaL9OLY6MqNg3Xy/ETw6wiwEhmppRyKfrCWZQIgMG3HcHWv5dOGumbeMXxXQjOYwQhgztBbOq2p2Q7KUgw="}],"size":1375337,"noattachment":false,"key":"/frac/-/frac-0.2.1.tgz"},"_from":".","_npmVersion":"1.3.14","_npmUser":{"name":"sheetjs","email":"dev@sheetjs.com"},"maintainers":[{"name":"sheetjs","email":"dev@sheetjs.com"}],"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":1388031274602,"_cnpm_publish_time":1388031274602,"dist-tags":{"latest":"1.1.2"}}