Compare commits

...

7 Commits

Author SHA1 Message Date
2e23313298 License text 2019-10-08 02:14:17 -04:00
373fc31e08 fixed travis config 2017-07-27 14:55:13 -04:00
616aabfb42 version bump 1.0.2: pin devDependencies 2017-07-27 14:22:02 -04:00
1c7de2c8f7 updated npm package 2017-01-05 16:36:45 -05:00
64765e5e98 version bump 1.0.0
- shifted from MIT to Apache 2.0 License
- updated travis versions and cleaned up build infrastructure
2017-01-05 15:04:15 -05:00
75ae1499db added browser test 2016-10-13 13:43:49 -04:00
73ee33e402 version bump 0.3.0: cleanup
- eliminated array reduce (performance improvement)
- explicit treatment of divergent values
- better handling of non-integral order (fixes #3, h/t @vron)
- reorganized source, removed voc dependency (fixes #2, h/t @hmalphettes)
- new browser demo
- more detailed test suite and coverage tests
- updated travis versions for test
- miscellaneous adjustments to tooling
2016-09-24 02:15:52 -04:00
40 changed files with 8416 additions and 123 deletions

21
.flowconfig Normal file

@ -0,0 +1,21 @@
[ignore]
.*/node_modules/.*
.*/dist/.*
.*/test.js
.*/bessel.js
.*/bits/.*
.*/ctest/.*
.*/misc/.*
.*/perf/.*
.*/demo/browser.js
.*/shim.js
[include]
bessel.flow.js
[libs]
bits/10_types.js
[options]

2
.gitignore vendored

@ -1 +1,3 @@
node_modules
misc/coverage.html
ctest/sauce*

6
.jscs.json Normal file

@ -0,0 +1,6 @@
{
"requireCommaBeforeLineBreak": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true
}

4
.jshintrc Normal file

@ -0,0 +1,4 @@
{
"bitwise": false,
"curly": false
}

@ -1,7 +1,17 @@
language: node_js
node_js:
- "0.11"
- "8"
- "7"
- "6"
- "5"
- "4"
- "0.12"
- "0.10"
- "0.8"
before_install:
- "npm install -g mocha"
- "npm install -g npm@4.3.0"
- "npm install -g mocha@2.x voc"
- "npm install blanket"
- "npm install coveralls mocha-lcov-reporter"
after_success:
- "make coveralls-spin"

202
LICENSE

@ -1,9 +1,201 @@
Copyright (C) 2013 SheetJS
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
The MIT License (MIT)
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1. Definitions.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright (C) 2013-present SheetJS LLC
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.

@ -1,7 +1,77 @@
LIBRARY=bessel
LIB=bessel
REQS=
ADDONS=
AUXTARGETS=
HTMLLINT=index.html
$(LIBRARY).js: bessel.md
node_modules/.bin/voc $^ > $@
ULIB=$(shell echo $(LIB) | tr a-z A-Z)
DEPS=$(sort $(wildcard bits/*.js))
TARGET=$(LIB).js
FLOWTARGET=$(LIB).flow.js
test mocha:
mocha -R spec
## Main Targets
.PHONY: all
all: $(TARGET) $(AUXTARGETS) ## Build library and auxiliary scripts
$(TARGET) $(AUXTARGETS): %.js : %.flow.js
node -e 'process.stdout.write(require("fs").readFileSync("$<","utf8").replace(/^[ \t]*\/\*[:#][^*]*\*\/\s*(\n)?/gm,"").replace(/\/\*[:#][^*]*\*\//gm,""))' > $@
$(FLOWTARGET): $(DEPS)
cat $^ | tr -d '\15\32' > $@
bits/01_version.js: package.json
echo "BESSEL.version = '"`grep version package.json | awk '{gsub(/[^0-9a-z\.-]/,"",$$2); print $$2}'`"';" > $@
.PHONY: clean
clean: ## Remove targets and build artifacts
rm -f $(TARGET) $(FLOWTARGET)
## Testing
.PHONY: test mocha
test mocha: test.js $(TARGET) ## Run test suite
mocha -R spec -t 20000
.PHONY: ctest
ctest: ## Build browser test (into ctest/ subdirectory)
cp -f test.js ctest/test.js
cp -f shim.js ctest/shim.js
cp -f $(TARGET) ctest/
.PHONY: ctestserv
ctestserv: ## Start a test server on port 8000
@cd ctest && python -mSimpleHTTPServer
## Code Checking
.PHONY: lint
lint: $(TARGET) $(AUXTARGETS) ## Run jshint and jscs checks
@jshint --show-non-errors $(TARGET) $(AUXTARGETS)
@jshint --show-non-errors package.json
@jshint --show-non-errors --extract=always $(HTMLLINT)
@jscs $(TARGET) $(AUXTARGETS)
.PHONY: flow
flow: lint ## Run flow checker
@flow check --all --show-all-errors
.PHONY: cov
cov: misc/coverage.html ## Run coverage test
misc/coverage.html: $(TARGET) test.js
mocha --require blanket -R html-cov -t 20000 > $@
.PHONY: coveralls
coveralls: ## Coverage Test + Send to coveralls.io
mocha --require blanket --reporter mocha-lcov-reporter -t 20000 | node ./node_modules/coveralls/bin/coveralls.js
.PHONY: help
help:
@grep -hE '(^[a-zA-Z_-][ a-zA-Z_-]*:.*?|^#[#*])' $(MAKEFILE_LIST) | bash misc/help.sh
#* To show a spinner, append "-spin" to any target e.g. cov-spin
%-spin:
@make $* & bash misc/spin.sh $$!

102
README.md

@ -1,36 +1,100 @@
# Bessel.JS
# bessel
Pure-JS implementation of the Bessel functions (J,Y,I,K), for node and browser
Pure-JS implementation of Bessel functions J,Y,I,K (for the browser and nodejs).
Emphasis on correctness and performance for integer order.
The standard notation is used here:
- J is the Bessel function of the first kind
- Y is the Bessel function of the second kind
- I is the modified Bessel function of the first kind
- K is the modified Bessel function of the first kind
- `J` is the Bessel function of the first kind
- `Y` is the Bessel function of the second kind
- `I` is the modified Bessel function of the first kind
- `K` is the modified Bessel function of the second kind
# Usage
## Installation
The functions `besselj`, `bessely`, `besseli`, `besselk` are exposed when you include
the script `bessel.js`:
With [npm](https://www.npmjs.org/package/bessel):
```html>
```bash
$ npm install bessel
```
In the browser:
```html
<script src="bessel.js"></script>
<script>console.log(besselj(1,2));</script>
```
See `test.html` for an example
The browser exposes a variable `BESSEL`
In node, those four functions are exported:
The script will manipulate `module.exports` if available (e.g. in a CommonJS
`require` context). This is not always desirable. To prevent the behavior,
define `DO_NOT_EXPORT_BESSEL`
```js>
var besselj01 = require('bessel').besselj(0,1);
## Usage
In all cases, the relevant function takes two arguments (`value`, `order`).
The return value is a JS number. `NaN` signals an error in calculation.
- `BESSEL.besselj(x, n)` computes `J_{n}(x)`
- `BESSEL.bessely(x, n)` computes `Y_{n}(x)`
- `BESSEL.besseli(x, n)` computes `I_{n}(x)`
- `BESSEL.besselk(x, n)` computes `K_{n}(x)`
For example:
```js
// var BESSEL = require('bessel'); // uncomment this line if in node
BESSEL.besselj(1.5,0) // 0.5118276712499389
BESSEL.bessely(1.5,0) // 0.38244892476502895
BESSEL.besseli(1.5,0) // 1.6467232021476754
BESSEL.besselk(1.5,0) // 0.2138055693236539
var Y = BESSEL.bessely
Y(Math.PI, 5) + Y(Math.PI, 3) - (2 * 4 / Math.PI) * Y(Math.PI, 4) // 0
```
Each function follows Excel semantics `(value, function-order)`. For example,
## Testing
```js>
bessel.besselj(1.5, 1)
`make test` will run the nodejs-based test.
To generate the `excel.tsv` test cases, make a 6-column Excel Sheet:
| x | n | `BESSELI` | `BESSELJ` | `BESSELK` | `BESSELY` |
|---|---|:--------------:|:--------------:|:--------------:|:--------------:|
| x | n |`BESSELI(A1,B1)`|`BESSELJ(A1,B1)`|`BESSELK(A1,B1)`|`BESSELY(A1,B1)`|
To generate the `mma.tsv` test cases, use the Mathematica Bessel Functions:
```mathematica
(* Bessel_[value, order] *)
F[x_,n_]:={x/2,n,BesselI[n,x/2], BesselJ[n,x/2], BesselK[n,x/2], BesselY[n,x/2]}
Do[Print[ExportString[N[F[x,n],10],"csv"]], {n,1,3}, {x,1,20} ]
```
is the value of the bessel function J1 at the point x=1.5
Note: Each function follows Excel semantics `(value, order)`. Other platforms
like Mathematica reverse the argument order.
## 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
[![Build Status](https://saucelabs.com/browser-matrix/bessel.svg)](https://saucelabs.com/u/bessel)
[![Build Status](https://travis-ci.org/SheetJS/bessel.svg?branch=master)](https://travis-ci.org/SheetJS/bessel)
[![Coverage Status](http://img.shields.io/coveralls/SheetJS/bessel/master.svg)](https://coveralls.io/r/SheetJS/bessel?branch=master)
[![NPM Downloads](https://img.shields.io/npm/dt/bessel.svg)](https://npmjs.org/package/bessel)
[![Dependencies Status](https://david-dm.org/sheetjs/bessel/status.svg)](https://david-dm.org/sheetjs/bessel)
[![ghit.me](https://ghit.me/badge.svg?repo=sheetjs/bessel)](https://ghit.me/repo/sheetjs/bessel)
[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/bessel?pixel)](https://github.com/SheetJS/bessel)

252
bessel.flow.js Normal file

@ -0,0 +1,252 @@
/* bessel.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*exported BESSEL */
var BESSEL;
/*:: declare var DO_NOT_EXPORT_BESSEL: any; */
/*:: declare var define: any; */
(function (factory) {
/*jshint ignore:start */
if(typeof DO_NOT_EXPORT_BESSEL === 'undefined') {
if('object' === typeof exports) {
factory(exports);
} else if ('function' === typeof define && define.amd) {
define(function () {
var module = {};
factory(module);
return module;
});
} else {
factory(BESSEL = {});
}
} else {
factory(BESSEL = {});
}
/*jshint ignore:end */
}(function(BESSEL) {
BESSEL.version = '1.0.2';
var M = Math;
/*::
type BesselN = (x:number) => number;
type BesselF = (x:number, n:number) => number;
*/
function _horner(arr/*:Array<number>*/, v/*:number*/)/*:number*/ { for(var i = 0, z = 0; i < arr.length; ++i) z = v * z + arr[i]; return z; }
function _bessel_iter(x/*:number*/, n/*:number*/, f0/*:number*/, f1/*:number*/, sign/*:number*/)/*:number*/ {
if(n === 0) return f0;
if(n === 1) return f1;
var tdx = 2 / x, f2 = f1;
for(var o = 1; o < n; ++o) {
f2 = f1 * o * tdx + sign * f0;
f0 = f1; f1 = f2;
}
return f2;
}
function _bessel_wrap(bessel0/*:BesselN*/, bessel1/*:BesselN*/, name/*:string*/, nonzero/*:number*/, sign/*:number*/)/*:BesselF*/ {
return function bessel(x/*:number*/,n/*:number*/) {
if(nonzero) {
if(x === 0) return (nonzero == 1 ? -Infinity : Infinity);
else if(x < 0) return NaN;
}
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(n < 0) return NaN;
n|=0;
var b0/*:number*/ = bessel0(x), b1/*:number*/ = bessel1(x);
return _bessel_iter(x, n, b0, b1, sign);
};
}
var besselj/*:BesselF*/ = (function() {
var W = 0.636619772; // 2 / Math.PI
var b0_a1a = [57568490574.0, -13362590354.0, 651619640.7, -11214424.18, 77392.33017, -184.9052456].reverse();
var b0_a2a = [57568490411.0, 1029532985.0, 9494680.718, 59272.64853, 267.8532712, 1.0].reverse();
var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse();
var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934935152e-7].reverse();
function bessel0(x/*:number*/)/*:number*/ {
var a=0, a1=0, a2=0, y = x * x;
if(x < 8) {
a1 = _horner(b0_a1a, y);
a2 = _horner(b0_a2a, y);
a = a1 / a2;
} else {
var xx = x - 0.785398164;
y = 64 / y;
a1 = _horner(b0_a1b, y);
a2 = _horner(b0_a2b, y);
a = M.sqrt(W/x)*(M.cos(xx)*a1-M.sin(xx)*a2*8/x);
}
return a;
}
var b1_a1a = [72362614232.0, -7895059235.0, 242396853.1, -2972611.439, 15704.48260, -30.16036606].reverse();
var b1_a2a = [144725228442.0, 2300535178.0, 18583304.74, 99447.43394, 376.9991397, 1.0].reverse();
var b1_a1b = [1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6].reverse();
var b1_a2b = [0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6].reverse();
function bessel1(x/*:number*/)/*:number*/ {
var a=0, a1=0, a2=0, y = x*x, xx = M.abs(x) - 2.356194491;
if(Math.abs(x)< 8) {
a1 = x*_horner(b1_a1a, y);
a2 = _horner(b1_a2a, y);
a = a1 / a2;
} else {
y = 64 / y;
a1=_horner(b1_a1b, y);
a2=_horner(b1_a2b, y);
a=M.sqrt(W/M.abs(x))*(M.cos(xx)*a1-M.sin(xx)*a2*8/M.abs(x));
if(x < 0) a = -a;
}
return a;
}
return function besselj(x/*:number*/, n/*:number*/)/*:number*/ {
n = Math.round(n);
if(!isFinite(x)) return isNaN(x) ? x : 0;
if(n < 0) return ((n%2)?-1:1)*besselj(x, -n);
if(x < 0) return ((n%2)?-1:1)*besselj(-x, n);
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(x === 0) return 0;
var ret=0.0;
if(x > n) {
ret = _bessel_iter(x, n, bessel0(x), bessel1(x),-1);
} else {
var m=2*M.floor((n+M.floor(M.sqrt(40*n)))/2);
var jsum=false;
var bjp=0.0, sum=0.0;
var bj=1.0, bjm = 0.0;
var tox = 2 / x;
for (var j=m;j>0;j--) {
bjm=j*tox*bj-bjp;
bjp=bj;
bj=bjm;
if (M.abs(bj) > 1E10) {
bj *= 1E-10;
bjp *= 1E-10;
ret *= 1E-10;
sum *= 1E-10;
}
if (jsum) sum += bj;
jsum=!jsum;
if (j == n) ret=bjp;
}
sum=2.0*sum-bj;
ret /= sum;
}
return ret;
};
})();
var bessely/*:BesselF*/ = (function() {
var W = 0.636619772;
var b0_a1a = [-2957821389.0, 7062834065.0, -512359803.6, 10879881.29, -86327.92757, 228.4622733].reverse();
var b0_a2a = [40076544269.0, 745249964.8, 7189466.438, 47447.26470, 226.1030244, 1.0].reverse();
var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse();
var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934945152e-7].reverse();
function bessel0(x/*:number*/)/*:number*/ {
var a=0, a1=0, a2=0, y = x * x, xx = x - 0.785398164;
if(x < 8) {
a1 = _horner(b0_a1a, y);
a2 = _horner(b0_a2a, y);
a = a1/a2 + W * besselj(x,0) * M.log(x);
} else {
y = 64 / y;
a1 = _horner(b0_a1b, y);
a2 = _horner(b0_a2b, y);
a = M.sqrt(W/x)*(M.sin(xx)*a1+M.cos(xx)*a2*8/x);
}
return a;
}
var b1_a1a = [-0.4900604943e13, 0.1275274390e13, -0.5153438139e11, 0.7349264551e9, -0.4237922726e7, 0.8511937935e4].reverse();
var b1_a2a = [0.2499580570e14, 0.4244419664e12, 0.3733650367e10, 0.2245904002e8, 0.1020426050e6, 0.3549632885e3, 1].reverse();
var b1_a1b = [1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6].reverse();
var b1_a2b = [0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6].reverse();
function bessel1(x/*:number*/)/*:number*/ {
var a=0, a1=0, a2=0, y = x*x, xx = x - 2.356194491;
if(x < 8) {
a1 = x*_horner(b1_a1a, y);
a2 = _horner(b1_a2a, y);
a = a1/a2 + W * (besselj(x,1) * M.log(x) - 1 / x);
} else {
y = 64 / y;
a1=_horner(b1_a1b, y);
a2=_horner(b1_a2b, y);
a=M.sqrt(W/x)*(M.sin(xx)*a1+M.cos(xx)*a2*8/x);
}
return a;
}
return _bessel_wrap(bessel0, bessel1, 'BESSELY', 1, -1);
})();
var besseli/*:BesselF*/ = (function() {
var b0_a = [1.0, 3.5156229, 3.0899424, 1.2067492, 0.2659732, 0.360768e-1, 0.45813e-2].reverse();
var b0_b = [0.39894228, 0.1328592e-1, 0.225319e-2, -0.157565e-2, 0.916281e-2, -0.2057706e-1, 0.2635537e-1, -0.1647633e-1, 0.392377e-2].reverse();
function bessel0(x/*:number*/)/*:number*/ {
if(x <= 3.75) return _horner(b0_a, x*x/(3.75*3.75));
return M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b0_b, 3.75/M.abs(x));
}
var b1_a = [0.5, 0.87890594, 0.51498869, 0.15084934, 0.2658733e-1, 0.301532e-2, 0.32411e-3].reverse();
var b1_b = [0.39894228, -0.3988024e-1, -0.362018e-2, 0.163801e-2, -0.1031555e-1, 0.2282967e-1, -0.2895312e-1, 0.1787654e-1, -0.420059e-2].reverse();
function bessel1(x/*:number*/)/*:number*/ {
if(x < 3.75) return x * _horner(b1_a, x*x/(3.75*3.75));
return (x < 0 ? -1 : 1) * M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b1_b, 3.75/M.abs(x));
}
return function besseli(x/*:number*/, n/*:number*/)/*:number*/ {
n = Math.round(n);
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(n < 0) return NaN;
if(M.abs(x) === 0) return 0;
if(x == Infinity) return Infinity;
var ret = 0.0, j, tox = 2 / M.abs(x), bip = 0.0, bi=1.0, bim=0.0;
var m=2*M.round((n+M.round(M.sqrt(40*n)))/2);
for (j=m;j>0;j--) {
bim=j*tox*bi + bip;
bip=bi; bi=bim;
if (M.abs(bi) > 1E10) {
bi *= 1E-10;
bip *= 1E-10;
ret *= 1E-10;
}
if(j == n) ret = bip;
}
ret *= besseli(x, 0) / bi;
return x < 0 && (n%2) ? -ret : ret;
};
})();
var besselk/*:BesselF*/ = (function() {
var b0_a = [-0.57721566, 0.42278420, 0.23069756, 0.3488590e-1, 0.262698e-2, 0.10750e-3, 0.74e-5].reverse();
var b0_b = [1.25331414, -0.7832358e-1, 0.2189568e-1, -0.1062446e-1, 0.587872e-2, -0.251540e-2, 0.53208e-3].reverse();
function bessel0(x/*:number*/)/*:number*/ {
if(x <= 2) return -M.log(x/2) * besseli(x,0) + _horner(b0_a, x*x/4);
return M.exp(-x) / M.sqrt(x) * _horner(b0_b, 2/x);
}
var b1_a = [1.0, 0.15443144, -0.67278579, -0.18156897, -0.1919402e-1, -0.110404e-2, -0.4686e-4].reverse();
var b1_b = [1.25331414, 0.23498619, -0.3655620e-1, 0.1504268e-1, -0.780353e-2, 0.325614e-2, -0.68245e-3].reverse();
function bessel1(x/*:number*/)/*:number*/ {
if(x <= 2) return M.log(x/2) * besseli(x,1) + (1/x) * _horner(b1_a, x*x/4);
return M.exp(-x)/M.sqrt(x)*_horner(b1_b, 2/x);
}
return _bessel_wrap(bessel0, bessel1, 'BESSELK', 2, 1);
})();
BESSEL.besselj = besselj;
BESSEL.bessely = bessely;
BESSEL.besseli = besseli;
BESSEL.besselk = besselk;
}));

141
bessel.js

@ -1,55 +1,85 @@
/* bessel.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*exported BESSEL */
var BESSEL;
(function (factory) {
/*jshint ignore:start */
if(typeof DO_NOT_EXPORT_BESSEL === 'undefined') {
if('object' === typeof exports) {
factory(exports);
} else if ('function' === typeof define && define.amd) {
define(function () {
var module = {};
factory(module);
return module;
});
} else {
factory(BESSEL = {});
}
} else {
factory(BESSEL = {});
}
/*jshint ignore:end */
}(function(BESSEL) {
BESSEL.version = '1.0.2';
var M = Math;
function _horner(arr, v) { return arr.reduce(function(z,w){return v * z + w;},0); };
function _horner(arr, v) { for(var i = 0, z = 0; i < arr.length; ++i) z = v * z + arr[i]; return z; }
function _bessel_iter(x, n, f0, f1, sign) {
if(!sign) sign = -1;
var tdx = 2 / x, f2;
if(n === 0) return f0;
if(n === 1) return f1;
for(var o = 1; o != n; ++o) {
var tdx = 2 / x, f2 = f1;
for(var o = 1; o < n; ++o) {
f2 = f1 * o * tdx + sign * f0;
f0 = f1; f1 = f2;
}
return f1;
return f2;
}
function _bessel_wrap(bessel0, bessel1, name, nonzero, sign) {
return function bessel(x,n) {
if(nonzero) {
if(x === 0) return (nonzero == 1 ? -Infinity : Infinity);
else if(x < 0) return NaN;
}
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(n < 0) throw name + ': Order (' + n + ') must be nonnegative';
if(nonzero == 1 && x === 0) throw name + ': Undefined when x == 0';
if(nonzero == 2 && x <= 0) throw name + ': Undefined when x <= 0';
if(n < 0) return NaN;
n|=0;
var b0 = bessel0(x), b1 = bessel1(x);
return _bessel_iter(x, n, b0, b1, sign);
};
}
var besselj = (function() {
var b0_a1a = [57568490574.0,-13362590354.0,651619640.7,-11214424.18,77392.33017,-184.9052456].reverse();
var b0_a2a = [57568490411.0,1029532985.0,9494680.718,59272.64853,267.8532712,1.0].reverse();
var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse();
var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934935152e-7].reverse();
var W = 0.636619772; // 2 / Math.PI
var b0_a1a = [57568490574.0, -13362590354.0, 651619640.7, -11214424.18, 77392.33017, -184.9052456].reverse();
var b0_a2a = [57568490411.0, 1029532985.0, 9494680.718, 59272.64853, 267.8532712, 1.0].reverse();
var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse();
var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934935152e-7].reverse();
function bessel0(x) {
var a, a1, a2, y = x * x, xx = M.abs(x) - 0.785398164;
if(M.abs(x) < 8) {
var a=0, a1=0, a2=0, y = x * x;
if(x < 8) {
a1 = _horner(b0_a1a, y);
a2 = _horner(b0_a2a, y);
a = a1/a2;
}
else {
a = a1 / a2;
} else {
var xx = x - 0.785398164;
y = 64 / y;
a1 = _horner(b0_a1b, y);
a2 = _horner(b0_a2b, y);
a = M.sqrt(W/M.abs(x))*(M.cos(xx)*a1-M.sin(xx)*a2*8/M.abs(x));
a = M.sqrt(W/x)*(M.cos(xx)*a1-M.sin(xx)*a2*8/x);
}
return a;
}
var b1_a1a = [72362614232.0,-7895059235.0,242396853.1,-2972611.439, 15704.48260, -30.16036606].reverse();
var b1_a1a = [72362614232.0, -7895059235.0, 242396853.1, -2972611.439, 15704.48260, -30.16036606].reverse();
var b1_a2a = [144725228442.0, 2300535178.0, 18583304.74, 99447.43394, 376.9991397, 1.0].reverse();
var b1_a1b = [1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6].reverse();
var b1_a2b = [0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6].reverse();
function bessel1(x) {
var a, a1, a2, y = x*x, xx = M.abs(x) - 2.356194491;
var a=0, a1=0, a2=0, y = x*x, xx = M.abs(x) - 2.356194491;
if(Math.abs(x)< 8) {
a1 = x*_horner(b1_a1a, y);
a2 = _horner(b1_a2a, y);
@ -63,22 +93,26 @@ var besselj = (function() {
}
return a;
}
return function besselj(x, n) {
n = Math.round(n);
if(n === 0) return bessel0(M.abs(x));
if(n === 1) return bessel1(M.abs(x));
if(n < 0) throw 'BESSELJ: Order (' + n + ') must be nonnegative';
if(M.abs(x) === 0) return 0;
if(!isFinite(x)) return isNaN(x) ? x : 0;
if(n < 0) return ((n%2)?-1:1)*besselj(x, -n);
if(x < 0) return ((n%2)?-1:1)*besselj(-x, n);
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(x === 0) return 0;
var ret, j, tox = 2 / M.abs(x), m, jsum, sum, bjp, bj, bjm;
if(M.abs(x) > n) {
ret = _bessel_iter(x, n, bessel0(M.abs(x)), bessel1(M.abs(x)),-1);
var ret=0.0;
if(x > n) {
ret = _bessel_iter(x, n, bessel0(x), bessel1(x),-1);
} else {
m=2*M.floor((n+M.floor(M.sqrt(40*n)))/2);
jsum=0;
bjp=ret=sum=0.0;
bj=1.0;
for (j=m;j>0;j--) {
var m=2*M.floor((n+M.floor(M.sqrt(40*n)))/2);
var jsum=false;
var bjp=0.0, sum=0.0;
var bj=1.0, bjm = 0.0;
var tox = 2 / x;
for (var j=m;j>0;j--) {
bjm=j*tox*bj-bjp;
bjp=bj;
bj=bjm;
@ -95,18 +129,19 @@ var besselj = (function() {
sum=2.0*sum-bj;
ret /= sum;
}
return x < 0 && (n%2) ? -ret : ret;
return ret;
};
})();
var bessely = (function() {
var W = 0.636619772;
var b0_a1a = [-2957821389.0, 7062834065.0, -512359803.6, 10879881.29, -86327.92757, 228.4622733].reverse();
var b0_a2a = [40076544269.0, 745249964.8, 7189466.438, 47447.26470, 226.1030244, 1.0].reverse();
var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse();
var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934945152e-7].reverse();
var W = 0.636619772;
function bessel0(x) {
var a, a1, a2, y = x * x, xx = x - 0.785398164;
var a=0, a1=0, a2=0, y = x * x, xx = x - 0.785398164;
if(x < 8) {
a1 = _horner(b0_a1a, y);
a2 = _horner(b0_a2a, y);
@ -124,8 +159,9 @@ var bessely = (function() {
var b1_a2a = [0.2499580570e14, 0.4244419664e12, 0.3733650367e10, 0.2245904002e8, 0.1020426050e6, 0.3549632885e3, 1].reverse();
var b1_a1b = [1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6].reverse();
var b1_a2b = [0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6].reverse();
function bessel1(x) {
var a, a1, a2, y = x*x, xx = x - 2.356194491;
var a=0, a1=0, a2=0, y = x*x, xx = x - 2.356194491;
if(x < 8) {
a1 = x*_horner(b1_a1a, y);
a2 = _horner(b1_a2a, y);
@ -144,6 +180,7 @@ var bessely = (function() {
var besseli = (function() {
var b0_a = [1.0, 3.5156229, 3.0899424, 1.2067492, 0.2659732, 0.360768e-1, 0.45813e-2].reverse();
var b0_b = [0.39894228, 0.1328592e-1, 0.225319e-2, -0.157565e-2, 0.916281e-2, -0.2057706e-1, 0.2635537e-1, -0.1647633e-1, 0.392377e-2].reverse();
function bessel0(x) {
if(x <= 3.75) return _horner(b0_a, x*x/(3.75*3.75));
return M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b0_b, 3.75/M.abs(x));
@ -151,6 +188,7 @@ var besseli = (function() {
var b1_a = [0.5, 0.87890594, 0.51498869, 0.15084934, 0.2658733e-1, 0.301532e-2, 0.32411e-3].reverse();
var b1_b = [0.39894228, -0.3988024e-1, -0.362018e-2, 0.163801e-2, -0.1031555e-1, 0.2282967e-1, -0.2895312e-1, 0.1787654e-1, -0.420059e-2].reverse();
function bessel1(x) {
if(x < 3.75) return x * _horner(b1_a, x*x/(3.75*3.75));
return (x < 0 ? -1 : 1) * M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b1_b, 3.75/M.abs(x));
@ -159,14 +197,13 @@ var besseli = (function() {
return function besseli(x, n) {
n = Math.round(n);
if(n === 0) return bessel0(x);
if(n == 1) return bessel1(x);
if(n < 0) throw 'BESSELI Order (' + n + ') must be nonnegative';
if(n === 1) return bessel1(x);
if(n < 0) return NaN;
if(M.abs(x) === 0) return 0;
if(x == Infinity) return Infinity;
var ret, j, tox = 2 / M.abs(x), m, bip, bi, bim;
m=2*M.round((n+M.round(M.sqrt(40*n)))/2);
bip=ret=0.0;
bi=1.0;
var ret = 0.0, j, tox = 2 / M.abs(x), bip = 0.0, bi=1.0, bim=0.0;
var m=2*M.round((n+M.round(M.sqrt(40*n)))/2);
for (j=m;j>0;j--) {
bim=j*tox*bi + bip;
bip=bi; bi=bim;
@ -186,24 +223,24 @@ var besseli = (function() {
var besselk = (function() {
var b0_a = [-0.57721566, 0.42278420, 0.23069756, 0.3488590e-1, 0.262698e-2, 0.10750e-3, 0.74e-5].reverse();
var b0_b = [1.25331414, -0.7832358e-1, 0.2189568e-1, -0.1062446e-1, 0.587872e-2, -0.251540e-2, 0.53208e-3].reverse();
function bessel0(x) {
if(x <= 2) return -M.log(x/2)*besseli(x,0) + _horner(b0_a, x*x/4);
return M.exp(-x)/M.sqrt(x)*_horner(b0_b, 2/x);
if(x <= 2) return -M.log(x/2) * besseli(x,0) + _horner(b0_a, x*x/4);
return M.exp(-x) / M.sqrt(x) * _horner(b0_b, 2/x);
}
var b1_a = [1.0, 0.15443144, -0.67278579, -0.18156897, -0.1919402e-1, -0.110404e-2, -0.4686e-4].reverse();
var b1_b = [1.25331414, 0.23498619, -0.3655620e-1, 0.1504268e-1, -0.780353e-2, 0.325614e-2, -0.68245e-3].reverse();
function bessel1(x) {
if(x <= 2) return M.log(x/2)*besseli(x,1) + (1/x)*_horner(b1_a, x*x/4);
if(x <= 2) return M.log(x/2) * besseli(x,1) + (1/x) * _horner(b1_a, x*x/4);
return M.exp(-x)/M.sqrt(x)*_horner(b1_b, 2/x);
}
return _bessel_wrap(bessel0, bessel1, 'BESSELK', 2, 1);
})();
if(typeof exports !== "undefined") {
exports.besselj = besselj;
exports.bessely = bessely;
exports.besseli = besseli;
exports.besselk = besselk;
}
BESSEL.besselj = besselj;
BESSEL.bessely = bessely;
BESSEL.besseli = besseli;
BESSEL.besselk = besselk;
}));

@ -14,7 +14,7 @@ var M = Math;
The methods use an approximating polynomial and evaluate using Horner's method:
```
function _horner(arr, v) { return arr.reduce(function(z,w){return v * z + w;},0); };
function _horner(arr/*:Array<number>*/, v/*:number*/) { return arr.reduce(function(z,w){return v * z + w;},0); }
```
## Recurrence
@ -29,7 +29,7 @@ So rather than go back and try to find solution for each order, we will build
solutions for `n=0` and `n=1` and then apply the recurrence. The helper:
```js
function _bessel_iter(x, n, f0, f1, sign) {
function _bessel_iter(x/*:number*/, n/*:number*/, f0/*:number*/, f1/*:number*/, sign/*:?number*/) {
if(!sign) sign = -1;
var tdx = 2 / x, f2;
if(n === 0) return f0;
@ -48,7 +48,7 @@ checks since `Y_n` is undefined at 0 and `K_n` is real only when `x>0`
```
function _bessel_wrap(bessel0, bessel1, name, nonzero, sign) {
return function bessel(x,n) {
return function bessel(x/*:number*/,n/*:number*/) {
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(n < 0) throw name + ': Order (' + n + ') must be nonnegative';
@ -143,7 +143,7 @@ For large values of x, the aforementioned iteration is fine, but for small
values the expressions quickly blow up. Hence a more careful iteration is used:
```
return function besselj(x, n) {
return function besselj(x/*:number*/, n/*:number*/) {
n = Math.round(n);
if(n === 0) return bessel0(M.abs(x));
if(n === 1) return bessel1(M.abs(x));
@ -246,7 +246,7 @@ var besseli = (function() {
return (x < 0 ? -1 : 1) * M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b1_b, 3.75/M.abs(x));
}
return function besseli(x, n) {
return function besseli(x/*:number*/, n/*:number*/) {
n = Math.round(n);
if(n === 0) return bessel0(x);
if(n == 1) return bessel1(x);

25
bits/00_header.js Normal file

@ -0,0 +1,25 @@
/* bessel.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*exported BESSEL */
var BESSEL;
/*:: declare var DO_NOT_EXPORT_BESSEL: any; */
/*:: declare var define: any; */
(function (factory) {
/*jshint ignore:start */
if(typeof DO_NOT_EXPORT_BESSEL === 'undefined') {
if('object' === typeof exports) {
factory(exports);
} else if ('function' === typeof define && define.amd) {
define(function () {
var module = {};
factory(module);
return module;
});
} else {
factory(BESSEL = {});
}
} else {
factory(BESSEL = {});
}
/*jshint ignore:end */
}(function(BESSEL) {

1
bits/01_version.js Normal file

@ -0,0 +1 @@
BESSEL.version = '1.0.2';

2
bits/02_helpers.js Normal file

@ -0,0 +1,2 @@
var M = Math;

4
bits/10_types.js Normal file

@ -0,0 +1,4 @@
/*::
type BesselN = (x:number) => number;
type BesselF = (x:number, n:number) => number;
*/

1
bits/20_helpers.js Normal file

@ -0,0 +1 @@
function _horner(arr/*:Array<number>*/, v/*:number*/)/*:number*/ { for(var i = 0, z = 0; i < arr.length; ++i) z = v * z + arr[i]; return z; }

10
bits/30_iter.js Normal file

@ -0,0 +1,10 @@
function _bessel_iter(x/*:number*/, n/*:number*/, f0/*:number*/, f1/*:number*/, sign/*:number*/)/*:number*/ {
if(n === 0) return f0;
if(n === 1) return f1;
var tdx = 2 / x, f2 = f1;
for(var o = 1; o < n; ++o) {
f2 = f1 * o * tdx + sign * f0;
f0 = f1; f1 = f2;
}
return f2;
}

14
bits/40_wrapper.js Normal file

@ -0,0 +1,14 @@
function _bessel_wrap(bessel0/*:BesselN*/, bessel1/*:BesselN*/, name/*:string*/, nonzero/*:number*/, sign/*:number*/)/*:BesselF*/ {
return function bessel(x/*:number*/,n/*:number*/) {
if(nonzero) {
if(x === 0) return (nonzero == 1 ? -Infinity : Infinity);
else if(x < 0) return NaN;
}
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(n < 0) return NaN;
n|=0;
var b0/*:number*/ = bessel0(x), b1/*:number*/ = bessel1(x);
return _bessel_iter(x, n, b0, b1, sign);
};
}

83
bits/50_besselj.js Normal file

@ -0,0 +1,83 @@
var besselj/*:BesselF*/ = (function() {
var W = 0.636619772; // 2 / Math.PI
var b0_a1a = [57568490574.0, -13362590354.0, 651619640.7, -11214424.18, 77392.33017, -184.9052456].reverse();
var b0_a2a = [57568490411.0, 1029532985.0, 9494680.718, 59272.64853, 267.8532712, 1.0].reverse();
var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse();
var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934935152e-7].reverse();
function bessel0(x/*:number*/)/*:number*/ {
var a=0, a1=0, a2=0, y = x * x;
if(x < 8) {
a1 = _horner(b0_a1a, y);
a2 = _horner(b0_a2a, y);
a = a1 / a2;
} else {
var xx = x - 0.785398164;
y = 64 / y;
a1 = _horner(b0_a1b, y);
a2 = _horner(b0_a2b, y);
a = M.sqrt(W/x)*(M.cos(xx)*a1-M.sin(xx)*a2*8/x);
}
return a;
}
var b1_a1a = [72362614232.0, -7895059235.0, 242396853.1, -2972611.439, 15704.48260, -30.16036606].reverse();
var b1_a2a = [144725228442.0, 2300535178.0, 18583304.74, 99447.43394, 376.9991397, 1.0].reverse();
var b1_a1b = [1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6].reverse();
var b1_a2b = [0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6].reverse();
function bessel1(x/*:number*/)/*:number*/ {
var a=0, a1=0, a2=0, y = x*x, xx = M.abs(x) - 2.356194491;
if(Math.abs(x)< 8) {
a1 = x*_horner(b1_a1a, y);
a2 = _horner(b1_a2a, y);
a = a1 / a2;
} else {
y = 64 / y;
a1=_horner(b1_a1b, y);
a2=_horner(b1_a2b, y);
a=M.sqrt(W/M.abs(x))*(M.cos(xx)*a1-M.sin(xx)*a2*8/M.abs(x));
if(x < 0) a = -a;
}
return a;
}
return function besselj(x/*:number*/, n/*:number*/)/*:number*/ {
n = Math.round(n);
if(!isFinite(x)) return isNaN(x) ? x : 0;
if(n < 0) return ((n%2)?-1:1)*besselj(x, -n);
if(x < 0) return ((n%2)?-1:1)*besselj(-x, n);
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(x === 0) return 0;
var ret=0.0;
if(x > n) {
ret = _bessel_iter(x, n, bessel0(x), bessel1(x),-1);
} else {
var m=2*M.floor((n+M.floor(M.sqrt(40*n)))/2);
var jsum=false;
var bjp=0.0, sum=0.0;
var bj=1.0, bjm = 0.0;
var tox = 2 / x;
for (var j=m;j>0;j--) {
bjm=j*tox*bj-bjp;
bjp=bj;
bj=bjm;
if (M.abs(bj) > 1E10) {
bj *= 1E-10;
bjp *= 1E-10;
ret *= 1E-10;
sum *= 1E-10;
}
if (jsum) sum += bj;
jsum=!jsum;
if (j == n) ret=bjp;
}
sum=2.0*sum-bj;
ret /= sum;
}
return ret;
};
})();

45
bits/60_bessely.js Normal file

@ -0,0 +1,45 @@
var bessely/*:BesselF*/ = (function() {
var W = 0.636619772;
var b0_a1a = [-2957821389.0, 7062834065.0, -512359803.6, 10879881.29, -86327.92757, 228.4622733].reverse();
var b0_a2a = [40076544269.0, 745249964.8, 7189466.438, 47447.26470, 226.1030244, 1.0].reverse();
var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse();
var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934945152e-7].reverse();
function bessel0(x/*:number*/)/*:number*/ {
var a=0, a1=0, a2=0, y = x * x, xx = x - 0.785398164;
if(x < 8) {
a1 = _horner(b0_a1a, y);
a2 = _horner(b0_a2a, y);
a = a1/a2 + W * besselj(x,0) * M.log(x);
} else {
y = 64 / y;
a1 = _horner(b0_a1b, y);
a2 = _horner(b0_a2b, y);
a = M.sqrt(W/x)*(M.sin(xx)*a1+M.cos(xx)*a2*8/x);
}
return a;
}
var b1_a1a = [-0.4900604943e13, 0.1275274390e13, -0.5153438139e11, 0.7349264551e9, -0.4237922726e7, 0.8511937935e4].reverse();
var b1_a2a = [0.2499580570e14, 0.4244419664e12, 0.3733650367e10, 0.2245904002e8, 0.1020426050e6, 0.3549632885e3, 1].reverse();
var b1_a1b = [1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6].reverse();
var b1_a2b = [0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6].reverse();
function bessel1(x/*:number*/)/*:number*/ {
var a=0, a1=0, a2=0, y = x*x, xx = x - 2.356194491;
if(x < 8) {
a1 = x*_horner(b1_a1a, y);
a2 = _horner(b1_a2a, y);
a = a1/a2 + W * (besselj(x,1) * M.log(x) - 1 / x);
} else {
y = 64 / y;
a1=_horner(b1_a1b, y);
a2=_horner(b1_a2b, y);
a=M.sqrt(W/x)*(M.sin(xx)*a1+M.cos(xx)*a2*8/x);
}
return a;
}
return _bessel_wrap(bessel0, bessel1, 'BESSELY', 1, -1);
})();

43
bits/70_besseli.js Normal file

@ -0,0 +1,43 @@
var besseli/*:BesselF*/ = (function() {
var b0_a = [1.0, 3.5156229, 3.0899424, 1.2067492, 0.2659732, 0.360768e-1, 0.45813e-2].reverse();
var b0_b = [0.39894228, 0.1328592e-1, 0.225319e-2, -0.157565e-2, 0.916281e-2, -0.2057706e-1, 0.2635537e-1, -0.1647633e-1, 0.392377e-2].reverse();
function bessel0(x/*:number*/)/*:number*/ {
if(x <= 3.75) return _horner(b0_a, x*x/(3.75*3.75));
return M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b0_b, 3.75/M.abs(x));
}
var b1_a = [0.5, 0.87890594, 0.51498869, 0.15084934, 0.2658733e-1, 0.301532e-2, 0.32411e-3].reverse();
var b1_b = [0.39894228, -0.3988024e-1, -0.362018e-2, 0.163801e-2, -0.1031555e-1, 0.2282967e-1, -0.2895312e-1, 0.1787654e-1, -0.420059e-2].reverse();
function bessel1(x/*:number*/)/*:number*/ {
if(x < 3.75) return x * _horner(b1_a, x*x/(3.75*3.75));
return (x < 0 ? -1 : 1) * M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b1_b, 3.75/M.abs(x));
}
return function besseli(x/*:number*/, n/*:number*/)/*:number*/ {
n = Math.round(n);
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(n < 0) return NaN;
if(M.abs(x) === 0) return 0;
if(x == Infinity) return Infinity;
var ret = 0.0, j, tox = 2 / M.abs(x), bip = 0.0, bi=1.0, bim=0.0;
var m=2*M.round((n+M.round(M.sqrt(40*n)))/2);
for (j=m;j>0;j--) {
bim=j*tox*bi + bip;
bip=bi; bi=bim;
if (M.abs(bi) > 1E10) {
bi *= 1E-10;
bip *= 1E-10;
ret *= 1E-10;
}
if(j == n) ret = bip;
}
ret *= besseli(x, 0) / bi;
return x < 0 && (n%2) ? -ret : ret;
};
})();

19
bits/80_besselk.js Normal file

@ -0,0 +1,19 @@
var besselk/*:BesselF*/ = (function() {
var b0_a = [-0.57721566, 0.42278420, 0.23069756, 0.3488590e-1, 0.262698e-2, 0.10750e-3, 0.74e-5].reverse();
var b0_b = [1.25331414, -0.7832358e-1, 0.2189568e-1, -0.1062446e-1, 0.587872e-2, -0.251540e-2, 0.53208e-3].reverse();
function bessel0(x/*:number*/)/*:number*/ {
if(x <= 2) return -M.log(x/2) * besseli(x,0) + _horner(b0_a, x*x/4);
return M.exp(-x) / M.sqrt(x) * _horner(b0_b, 2/x);
}
var b1_a = [1.0, 0.15443144, -0.67278579, -0.18156897, -0.1919402e-1, -0.110404e-2, -0.4686e-4].reverse();
var b1_b = [1.25331414, 0.23498619, -0.3655620e-1, 0.1504268e-1, -0.780353e-2, 0.325614e-2, -0.68245e-3].reverse();
function bessel1(x/*:number*/)/*:number*/ {
if(x <= 2) return M.log(x/2) * besseli(x,1) + (1/x) * _horner(b1_a, x*x/4);
return M.exp(-x)/M.sqrt(x)*_horner(b1_b, 2/x);
}
return _bessel_wrap(bessel0, bessel1, 'BESSELK', 2, 1);
})();

4
bits/90_exports.js Normal file

@ -0,0 +1,4 @@
BESSEL.besselj = besselj;
BESSEL.bessely = bessely;
BESSEL.besseli = besseli;
BESSEL.besselk = besselk;

1
bits/99_footer.js Normal file

@ -0,0 +1 @@
}));

246
ctest/bessel.js Normal file

@ -0,0 +1,246 @@
/* bessel.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*exported BESSEL */
var BESSEL;
(function (factory) {
/*jshint ignore:start */
if(typeof DO_NOT_EXPORT_BESSEL === 'undefined') {
if('object' === typeof exports) {
factory(exports);
} else if ('function' === typeof define && define.amd) {
define(function () {
var module = {};
factory(module);
return module;
});
} else {
factory(BESSEL = {});
}
} else {
factory(BESSEL = {});
}
/*jshint ignore:end */
}(function(BESSEL) {
BESSEL.version = '1.0.2';
var M = Math;
function _horner(arr, v) { for(var i = 0, z = 0; i < arr.length; ++i) z = v * z + arr[i]; return z; }
function _bessel_iter(x, n, f0, f1, sign) {
if(n === 0) return f0;
if(n === 1) return f1;
var tdx = 2 / x, f2 = f1;
for(var o = 1; o < n; ++o) {
f2 = f1 * o * tdx + sign * f0;
f0 = f1; f1 = f2;
}
return f2;
}
function _bessel_wrap(bessel0, bessel1, name, nonzero, sign) {
return function bessel(x,n) {
if(nonzero) {
if(x === 0) return (nonzero == 1 ? -Infinity : Infinity);
else if(x < 0) return NaN;
}
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(n < 0) return NaN;
n|=0;
var b0 = bessel0(x), b1 = bessel1(x);
return _bessel_iter(x, n, b0, b1, sign);
};
}
var besselj = (function() {
var W = 0.636619772; // 2 / Math.PI
var b0_a1a = [57568490574.0, -13362590354.0, 651619640.7, -11214424.18, 77392.33017, -184.9052456].reverse();
var b0_a2a = [57568490411.0, 1029532985.0, 9494680.718, 59272.64853, 267.8532712, 1.0].reverse();
var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse();
var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934935152e-7].reverse();
function bessel0(x) {
var a=0, a1=0, a2=0, y = x * x;
if(x < 8) {
a1 = _horner(b0_a1a, y);
a2 = _horner(b0_a2a, y);
a = a1 / a2;
} else {
var xx = x - 0.785398164;
y = 64 / y;
a1 = _horner(b0_a1b, y);
a2 = _horner(b0_a2b, y);
a = M.sqrt(W/x)*(M.cos(xx)*a1-M.sin(xx)*a2*8/x);
}
return a;
}
var b1_a1a = [72362614232.0, -7895059235.0, 242396853.1, -2972611.439, 15704.48260, -30.16036606].reverse();
var b1_a2a = [144725228442.0, 2300535178.0, 18583304.74, 99447.43394, 376.9991397, 1.0].reverse();
var b1_a1b = [1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6].reverse();
var b1_a2b = [0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6].reverse();
function bessel1(x) {
var a=0, a1=0, a2=0, y = x*x, xx = M.abs(x) - 2.356194491;
if(Math.abs(x)< 8) {
a1 = x*_horner(b1_a1a, y);
a2 = _horner(b1_a2a, y);
a = a1 / a2;
} else {
y = 64 / y;
a1=_horner(b1_a1b, y);
a2=_horner(b1_a2b, y);
a=M.sqrt(W/M.abs(x))*(M.cos(xx)*a1-M.sin(xx)*a2*8/M.abs(x));
if(x < 0) a = -a;
}
return a;
}
return function besselj(x, n) {
n = Math.round(n);
if(!isFinite(x)) return isNaN(x) ? x : 0;
if(n < 0) return ((n%2)?-1:1)*besselj(x, -n);
if(x < 0) return ((n%2)?-1:1)*besselj(-x, n);
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(x === 0) return 0;
var ret=0.0;
if(x > n) {
ret = _bessel_iter(x, n, bessel0(x), bessel1(x),-1);
} else {
var m=2*M.floor((n+M.floor(M.sqrt(40*n)))/2);
var jsum=false;
var bjp=0.0, sum=0.0;
var bj=1.0, bjm = 0.0;
var tox = 2 / x;
for (var j=m;j>0;j--) {
bjm=j*tox*bj-bjp;
bjp=bj;
bj=bjm;
if (M.abs(bj) > 1E10) {
bj *= 1E-10;
bjp *= 1E-10;
ret *= 1E-10;
sum *= 1E-10;
}
if (jsum) sum += bj;
jsum=!jsum;
if (j == n) ret=bjp;
}
sum=2.0*sum-bj;
ret /= sum;
}
return ret;
};
})();
var bessely = (function() {
var W = 0.636619772;
var b0_a1a = [-2957821389.0, 7062834065.0, -512359803.6, 10879881.29, -86327.92757, 228.4622733].reverse();
var b0_a2a = [40076544269.0, 745249964.8, 7189466.438, 47447.26470, 226.1030244, 1.0].reverse();
var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse();
var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934945152e-7].reverse();
function bessel0(x) {
var a=0, a1=0, a2=0, y = x * x, xx = x - 0.785398164;
if(x < 8) {
a1 = _horner(b0_a1a, y);
a2 = _horner(b0_a2a, y);
a = a1/a2 + W * besselj(x,0) * M.log(x);
} else {
y = 64 / y;
a1 = _horner(b0_a1b, y);
a2 = _horner(b0_a2b, y);
a = M.sqrt(W/x)*(M.sin(xx)*a1+M.cos(xx)*a2*8/x);
}
return a;
}
var b1_a1a = [-0.4900604943e13, 0.1275274390e13, -0.5153438139e11, 0.7349264551e9, -0.4237922726e7, 0.8511937935e4].reverse();
var b1_a2a = [0.2499580570e14, 0.4244419664e12, 0.3733650367e10, 0.2245904002e8, 0.1020426050e6, 0.3549632885e3, 1].reverse();
var b1_a1b = [1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6].reverse();
var b1_a2b = [0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6].reverse();
function bessel1(x) {
var a=0, a1=0, a2=0, y = x*x, xx = x - 2.356194491;
if(x < 8) {
a1 = x*_horner(b1_a1a, y);
a2 = _horner(b1_a2a, y);
a = a1/a2 + W * (besselj(x,1) * M.log(x) - 1 / x);
} else {
y = 64 / y;
a1=_horner(b1_a1b, y);
a2=_horner(b1_a2b, y);
a=M.sqrt(W/x)*(M.sin(xx)*a1+M.cos(xx)*a2*8/x);
}
return a;
}
return _bessel_wrap(bessel0, bessel1, 'BESSELY', 1, -1);
})();
var besseli = (function() {
var b0_a = [1.0, 3.5156229, 3.0899424, 1.2067492, 0.2659732, 0.360768e-1, 0.45813e-2].reverse();
var b0_b = [0.39894228, 0.1328592e-1, 0.225319e-2, -0.157565e-2, 0.916281e-2, -0.2057706e-1, 0.2635537e-1, -0.1647633e-1, 0.392377e-2].reverse();
function bessel0(x) {
if(x <= 3.75) return _horner(b0_a, x*x/(3.75*3.75));
return M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b0_b, 3.75/M.abs(x));
}
var b1_a = [0.5, 0.87890594, 0.51498869, 0.15084934, 0.2658733e-1, 0.301532e-2, 0.32411e-3].reverse();
var b1_b = [0.39894228, -0.3988024e-1, -0.362018e-2, 0.163801e-2, -0.1031555e-1, 0.2282967e-1, -0.2895312e-1, 0.1787654e-1, -0.420059e-2].reverse();
function bessel1(x) {
if(x < 3.75) return x * _horner(b1_a, x*x/(3.75*3.75));
return (x < 0 ? -1 : 1) * M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b1_b, 3.75/M.abs(x));
}
return function besseli(x, n) {
n = Math.round(n);
if(n === 0) return bessel0(x);
if(n === 1) return bessel1(x);
if(n < 0) return NaN;
if(M.abs(x) === 0) return 0;
if(x == Infinity) return Infinity;
var ret = 0.0, j, tox = 2 / M.abs(x), bip = 0.0, bi=1.0, bim=0.0;
var m=2*M.round((n+M.round(M.sqrt(40*n)))/2);
for (j=m;j>0;j--) {
bim=j*tox*bi + bip;
bip=bi; bi=bim;
if (M.abs(bi) > 1E10) {
bi *= 1E-10;
bip *= 1E-10;
ret *= 1E-10;
}
if(j == n) ret = bip;
}
ret *= besseli(x, 0) / bi;
return x < 0 && (n%2) ? -ret : ret;
};
})();
var besselk = (function() {
var b0_a = [-0.57721566, 0.42278420, 0.23069756, 0.3488590e-1, 0.262698e-2, 0.10750e-3, 0.74e-5].reverse();
var b0_b = [1.25331414, -0.7832358e-1, 0.2189568e-1, -0.1062446e-1, 0.587872e-2, -0.251540e-2, 0.53208e-3].reverse();
function bessel0(x) {
if(x <= 2) return -M.log(x/2) * besseli(x,0) + _horner(b0_a, x*x/4);
return M.exp(-x) / M.sqrt(x) * _horner(b0_b, 2/x);
}
var b1_a = [1.0, 0.15443144, -0.67278579, -0.18156897, -0.1919402e-1, -0.110404e-2, -0.4686e-4].reverse();
var b1_b = [1.25331414, 0.23498619, -0.3655620e-1, 0.1504268e-1, -0.780353e-2, 0.325614e-2, -0.68245e-3].reverse();
function bessel1(x) {
if(x <= 2) return M.log(x/2) * besseli(x,1) + (1/x) * _horner(b1_a, x*x/4);
return M.exp(-x)/M.sqrt(x)*_horner(b1_b, 2/x);
}
return _bessel_wrap(bessel0, bessel1, 'BESSELK', 2, 1);
})();
BESSEL.besselj = besselj;
BESSEL.bessely = bessely;
BESSEL.besseli = besseli;
BESSEL.besselk = besselk;
}));

2
ctest/fakeassert.js Normal file

@ -0,0 +1,2 @@
var assert = {};
assert.equal = function(x,y) { if(x !== y) throw new Error(x + " !== " + y); };

23
ctest/index.html Normal file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Mocha</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="shim.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
<script src="bessel.js"></script>
<script src="fakeassert.js"></script>
<script src="mocha.js"></script>
<script src="sauce-client.js"></script>
<script>mocha.setup('bdd')</script>
<script src="test.js"></script>
<script>
mocha_sauce();
</script>
</body>
</html>

305
ctest/mocha.css Normal file

@ -0,0 +1,305 @@
@charset "utf-8";
body {
margin:0;
}
#mocha {
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: 60px 50px;
}
#mocha ul,
#mocha li {
margin: 0;
padding: 0;
}
#mocha ul {
list-style: none;
}
#mocha h1,
#mocha h2 {
margin: 0;
}
#mocha h1 {
margin-top: 15px;
font-size: 1em;
font-weight: 200;
}
#mocha h1 a {
text-decoration: none;
color: inherit;
}
#mocha h1 a:hover {
text-decoration: underline;
}
#mocha .suite .suite h1 {
margin-top: 0;
font-size: .8em;
}
#mocha .hidden {
display: none;
}
#mocha h2 {
font-size: 12px;
font-weight: normal;
cursor: pointer;
}
#mocha .suite {
margin-left: 15px;
}
#mocha .test {
margin-left: 15px;
overflow: hidden;
}
#mocha .test.pending:hover h2::after {
content: '(pending)';
font-family: arial, sans-serif;
}
#mocha .test.pass.medium .duration {
background: #c09853;
}
#mocha .test.pass.slow .duration {
background: #b94a48;
}
#mocha .test.pass::before {
content: '✓';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #00d6b2;
}
#mocha .test.pass .duration {
font-size: 9px;
margin-left: 5px;
padding: 2px 5px;
color: #fff;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
#mocha .test.pass.fast .duration {
display: none;
}
#mocha .test.pending {
color: #0b97c4;
}
#mocha .test.pending::before {
content: '◦';
color: #0b97c4;
}
#mocha .test.fail {
color: #c00;
}
#mocha .test.fail pre {
color: black;
}
#mocha .test.fail::before {
content: '✖';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #c00;
}
#mocha .test pre.error {
color: #c00;
max-height: 300px;
overflow: auto;
}
#mocha .test .html-error {
overflow: auto;
color: black;
line-height: 1.5;
display: block;
float: left;
clear: left;
font: 12px/1.5 monaco, monospace;
margin: 5px;
padding: 15px;
border: 1px solid #eee;
max-width: 85%; /*(1)*/
max-width: calc(100% - 42px); /*(2)*/
max-height: 300px;
word-wrap: break-word;
border-bottom-color: #ddd;
-webkit-border-radius: 3px;
-webkit-box-shadow: 0 1px 3px #eee;
-moz-border-radius: 3px;
-moz-box-shadow: 0 1px 3px #eee;
border-radius: 3px;
}
#mocha .test .html-error pre.error {
border: none;
-webkit-border-radius: none;
-webkit-box-shadow: none;
-moz-border-radius: none;
-moz-box-shadow: none;
padding: 0;
margin: 0;
margin-top: 18px;
max-height: none;
}
/**
* (1): approximate for browsers not supporting calc
* (2): 42 = 2*15 + 2*10 + 2*1 (padding + margin + border)
* ^^ seriously
*/
#mocha .test pre {
display: block;
float: left;
clear: left;
font: 12px/1.5 monaco, monospace;
margin: 5px;
padding: 15px;
border: 1px solid #eee;
max-width: 85%; /*(1)*/
max-width: calc(100% - 42px); /*(2)*/
word-wrap: break-word;
border-bottom-color: #ddd;
-webkit-border-radius: 3px;
-webkit-box-shadow: 0 1px 3px #eee;
-moz-border-radius: 3px;
-moz-box-shadow: 0 1px 3px #eee;
border-radius: 3px;
}
#mocha .test h2 {
position: relative;
}
#mocha .test a.replay {
position: absolute;
top: 3px;
right: 0;
text-decoration: none;
vertical-align: middle;
display: block;
width: 15px;
height: 15px;
line-height: 15px;
text-align: center;
background: #eee;
font-size: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
-webkit-transition: opacity 200ms;
-moz-transition: opacity 200ms;
transition: opacity 200ms;
opacity: 0.3;
color: #888;
}
#mocha .test:hover a.replay {
opacity: 1;
}
#mocha-report.pass .test.fail {
display: none;
}
#mocha-report.fail .test.pass {
display: none;
}
#mocha-report.pending .test.pass,
#mocha-report.pending .test.fail {
display: none;
}
#mocha-report.pending .test.pass.pending {
display: block;
}
#mocha-error {
color: #c00;
font-size: 1.5em;
font-weight: 100;
letter-spacing: 1px;
}
#mocha-stats {
position: fixed;
top: 15px;
right: 10px;
font-size: 12px;
margin: 0;
color: #888;
z-index: 1;
}
#mocha-stats .progress {
float: right;
padding-top: 0;
}
#mocha-stats em {
color: black;
}
#mocha-stats a {
text-decoration: none;
color: inherit;
}
#mocha-stats a:hover {
border-bottom: 1px solid #eee;
}
#mocha-stats li {
display: inline-block;
margin: 0 5px;
list-style: none;
padding-top: 11px;
}
#mocha-stats canvas {
width: 40px;
height: 40px;
}
#mocha code .comment { color: #ddd; }
#mocha code .init { color: #2f6fad; }
#mocha code .string { color: #5890ad; }
#mocha code .keyword { color: #8a6343; }
#mocha code .number { color: #2f6fad; }
@media screen and (max-device-width: 480px) {
#mocha {
margin: 60px 0px;
}
#mocha #stats {
position: absolute;
}
}

5842
ctest/mocha.js Normal file

File diff suppressed because it is too large Load Diff

237
ctest/shim.js Normal file

@ -0,0 +1,237 @@
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
if (!Object.keys) {
Object.keys = (function () {
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;
return function (obj) {
if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object');
var result = [];
for (var prop in obj) {
if (hasOwnProperty.call(obj, prop)) result.push(prop);
}
if (hasDontEnumBug) {
for (var i=0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
}
}
return result;
};
})();
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
if (!Array.prototype.filter)
{
Array.prototype.filter = function(fun /*, thisp */)
{
"use strict";
if (this == null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in t)
{
var val = t[i]; // in case fun mutates this
if (fun.call(thisp, val, i, t))
res.push(val);
}
}
return res;
};
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, '');
};
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisArg */)
{
"use strict";
if (this === void 0 || this === null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")
throw new TypeError();
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++)
{
if (i in t)
fun.call(thisArg, t[i], i, t);
}
};
}
// Production steps of ECMA-262, Edition 5, 15.4.4.19
// Reference: http://es5.github.com/#x15.4.4.19
if (!Array.prototype.map) {
Array.prototype.map = function(callback, thisArg) {
var T, A, k;
if (this == null) {
throw new TypeError(" this is null or not defined");
}
// 1. Let O be the result of calling ToObject passing the |this| value as the argument.
var O = Object(this);
// 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
// 3. Let len be ToUint32(lenValue).
var len = O.length >>> 0;
// 4. If IsCallable(callback) is false, throw a TypeError exception.
// See: http://es5.github.com/#x9.11
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (thisArg) {
T = thisArg;
}
// 6. Let A be a new array created as if by the expression new Array(len) where Array is
// the standard built-in constructor with that name and len is the value of len.
A = new Array(len);
// 7. Let k be 0
k = 0;
// 8. Repeat, while k < len
while(k < len) {
var kValue, mappedValue;
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
// b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
// This step can be combined with c
// c. If kPresent is true, then
if (k in O) {
// i. Let kValue be the result of calling the Get internal method of O with argument Pk.
kValue = O[ k ];
// ii. Let mappedValue be the result of calling the Call internal method of callback
// with T as the this value and argument list containing kValue, k, and O.
mappedValue = callback.call(T, kValue, k, O);
// iii. Call the DefineOwnProperty internal method of A with arguments
// Pk, Property Descriptor {Value: mappedValue, : true, Enumerable: true, Configurable: true},
// and false.
// In browsers that support Object.defineProperty, use the following:
// Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true });
// For best browser support, use the following:
A[ k ] = mappedValue;
}
// d. Increase k by 1.
k++;
}
// 9. return A
return A;
};
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
if ( this === undefined || this === null ) {
throw new TypeError( '"this" is null or not defined' );
}
var length = this.length >>> 0; // Hack to convert object.length to a UInt32
fromIndex = +fromIndex || 0;
if (Math.abs(fromIndex) === Infinity) {
fromIndex = 0;
}
if (fromIndex < 0) {
fromIndex += length;
if (fromIndex < 0) {
fromIndex = 0;
}
}
for (;fromIndex < length; fromIndex++) {
if (this[fromIndex] === searchElement) {
return fromIndex;
}
}
return -1;
};
}
// Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
if (! Array.isArray) {
Array.isArray = function(obj) {
return Object.prototype.toString.call(obj) === "[object Array]";
};
}
// https://github.com/ttaubert/node-arraybuffer-slice
// (c) 2013 Tim Taubert <tim@timtaubert.de>
// arraybuffer-slice may be freely distributed under the MIT license.
"use strict";
if (typeof ArrayBuffer !== 'undefined' && !ArrayBuffer.prototype.slice) {
ArrayBuffer.prototype.slice = function (begin, end) {
begin = (begin|0) || 0;
var num = this.byteLength;
end = end === (void 0) ? num : (end|0);
// Handle negative values.
if (begin < 0) begin += num;
if (end < 0) end += num;
if (num === 0 || begin >= num || begin >= end) {
return new ArrayBuffer(0);
}
var length = Math.min(num - begin, end - begin);
var target = new ArrayBuffer(length);
var targetArray = new Uint8Array(target);
targetArray.set(new Uint8Array(this, begin, length));
return target;
};
}

124
ctest/test.js Normal file

@ -0,0 +1,124 @@
/* vim: set ts=2: */
var X;
if(typeof require !== 'undefined') {
assert = require('assert');
describe('source',function(){
it('should load',function(){X=require('./');});
it('all bessel functions', function() {
assert.equal(typeof X.besseli, 'function');
assert.equal(typeof X.besselj, 'function');
assert.equal(typeof X.besselk, 'function');
assert.equal(typeof X.bessely, 'function');
});
});
} else { X = BESSEL; }
function approx(a, b, t) { return Math.abs((a - b) / (Math.abs(a) + Math.abs(b))) <= t; }
function chk(func, x, n, v, F, t) {
var V = func(x,n);
if(!approx(V, v, t) && v != V && !(isNaN(v) && isNaN(V))) throw new Error(F + "(" + x + "," + n + ") = " + V + " !~ " + v);
}
var funcs = ['besseli', 'besselj', 'besselk', 'bessely'];
var tests = {
'besseli': [
[1.5, 1, 0.981666],
[1.9, 2, 0.603272435],
[2.5, 1, 2.516716242]
],
'besselj': [
[1.5, 1, 0.557936508],
[1.9, 2, 0.329925829],
[2.5, 1, 0.497094103]
],
'besselk': [
[1.5, 1, 0.277388],
[1.9, 2, 0.296909301],
[2.5, 1, 0.073890816]
],
'bessely': [
[1.5, 1, -0.412308627],
[1.9, 2, -0.669878674],
[2.5, 1, 0.14591814]
] };
describe('correctness', function() {
funcs.forEach(function(F) { it(F, function() {
tests[F].forEach(function(t) { chk(X[F], t[0], t[1], t[2], F, 1e-6); });
});});
if(typeof require != 'undefined') {
var fs = require('fs');
it('excel', function() {
var xl = fs.readFileSync("test_files/excel.tsv", 'ascii').split("\n").map(function(l) { return l.split("\t");});
xl.forEach(function(l) { if(l.length < 6) return;
var x=Number(l[0]), n=Number(l[1]);
var i=Number(l[2]), j=Number(l[3]), k=Number(l[4]), y=Number(l[5]);
chk(X.besseli, x, n, i, 'besseli', 1e-4);
chk(X.besselj, x, n, j, 'besselj', 1e-4);
chk(X.besselk, x, n, k, 'besselk', 1e-4);
chk(X.bessely, x, n, y, 'bessely', 1e-4);
});
});
it('mma', function() {
var mma = fs.readFileSync("test_files/mma.tsv", 'ascii').split("\n").map(function(l) { return l.split("\t");});
mma.forEach(function(l) { if(l.length < 6) return;
var x=Number(l[0]), n=Number(l[1]);
var i=Number(l[2]), j=Number(l[3]), k=Number(l[4]), y=Number(l[5]);
chk(X.besseli, x, n, i, 'besseli', 1e-5);
chk(X.besselj, x, n, j, 'besselj', 1e-5);
chk(X.besselk, x, n, k, 'besselk', 1e-5);
chk(X.bessely, x, n, y, 'bessely', 1e-5);
});
});
}
});
var rand = [
0.3946086812775882, 3.946086812775882, 39.46086812775882,
0.03119419917289612, 0.3119419917289612, 3.119419917289612,
0.18311903629136062, 1.8311903629136062, 18.311903629136062,
0.5317681126599452, 5.317681126599452, 53.17681126599452,
0.37724541457032235, 3.7724541457032235, 37.724541457032235,
0.8287802926845655, 8.287802926845655, 82.87802926845655,
0.7197724866379658, 7.197724866379658, 71.97724866379658
];
describe('properties', function() {
var t = 1e-4;
it('limiting behavior', function() {
chk(X.besselj, 0, 0, 1, 'besselj', 1e-6);
chk(X.besseli, 0, 0, 1, 'besseli', 1e-6);
chk(X.besselk, 0, 0, Infinity, 'besselk', 1e-6);
chk(X.bessely, 0, 0, -Infinity, 'bessely', 1e-6);
for(var i = 1; i < 20; ++i) {
chk(X.besselj, 0, i, 0, 'besselj', 1e-6);
chk(X.besseli, 0, i, 0, 'besseli', 1e-6);
}
});
it('besselj', function() {
var F = "BESSELJ", f = X.besselj;
rand.forEach(function(r) {
for(var n = 0; n < 20; ++n) {
var pp = f( r, n), pn = f( r, -n), np = f(-r, n), nn = f(-r, -n);
if((n%2)) {
/* besselj odd if n is odd */
if(!approx(np, -pp, t)) throw new Error(F + " np[" + np + "] != -pp[" + (-pp) + "] (" + r + "," + n + ")");
if(!approx(nn, -pn, t)) throw new Error(F + " nn[" + nn + "] != -pn[" + (-pn) + "] (" + r + "," + n + ")");
/* asymmetric in n */
if(!approx(pn, -pp, t)) throw new Error(F + " pn[" + pn + "] != -pp[" + (-pp) + "] (" + r + "," + n + ")");
if(!approx(nn, -np, t)) throw new Error(F + " nn[" + nn + "] != -pn[" + (-pn) + "] (" + r + "," + n + ")");
} else {
/* besselj even if n is even */
if(!approx(np, pp, t)) throw new Error(F + " np[" + np + "] != pp[" + (pp) + "] (" + r + "," + n + ")");
if(!approx(nn, pn, t)) throw new Error(F + " nn[" + nn + "] != pn[" + (pn) + "] (" + r + "," + n + ")");
/* symmetric in n */
if(!approx(pn, pp, t)) throw new Error(F + " pn[" + pn + "] != pp[" + (pp) + "] (" + r + "," + n + ")");
if(!approx(nn, np, t)) throw new Error(F + " nn[" + nn + "] != pn[" + (pn) + "] (" + r + "," + n + ")");
}
}
});
});
});

84
index.html Normal file

@ -0,0 +1,84 @@
<!DOCTYPE html>
<!-- bessel.js (C) 2013-present SheetJS http://sheetjs.com -->
<!-- vim: set ts=2: -->
<html>
<head>
<title>Bessel Live Demo</title>
<script src="bessel.js"></script>
<script src="https://cdn.rawgit.com/SheetJS/printj/master/printj.js"></script>
</head>
<body>
<b>Bessel Live Demo</b><br />
<a href="https://github.com/SheetJS/bessel">Source Code</a><br />
<a href="https://github.com/SheetJS/bessel/issues">Issues? Something look weird? Click here and report an issue</a><br />
<br />
<table>
<tr><td><b>Number:</b></td><td><input type="text" id="val" value="1.5"></td></tr>
<tr><td><b>Order:</b></td><td><input type="text" id="ord" value="1"></td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2"><b><pre id="jt">J</pre></b></td></tr>
<tr><td colspan="2"><b><pre id="yt">Y</pre></b></td></tr>
<tr><td colspan="2"><b><pre id="it">I</pre></b></td></tr>
<tr><td colspan="2"><b><pre id="kt">K</pre></b></td></tr>
</table>
</body>
<script>
/*jshint browser:true */
var V = document.getElementById('val');
var O = document.getElementById('ord');
var J = document.getElementById('jt');
var Y = document.getElementById('yt');
var I = document.getElementById('it');
var K = document.getElementById('kt');
function update() {
var v = Number(V.value);
var o = Number(O.value);
if(v !== v) { J.innerHTML=Y.innerHTML=I.innerHTML=K.innerHTML = "Value |" + V.value + "| not valid"; return; }
if(o !== o) { J.innerHTML=Y.innerHTML=I.innerHTML=K.innerHTML = "Order |" + O.value + "| not valid"; return; }
o |= 0;
try { J.innerHTML = PRINTJ.sprintf("J(%.11g, %d) = %+.11g", v, o, BESSEL.besselj(v, o)); } catch(e) { J.innerHTML = String(e); }
try { Y.innerHTML = PRINTJ.sprintf("Y(%.11g, %d) = %+.11g", v, o, BESSEL.bessely(v, o)); } catch(e) { Y.innerHTML = String(e); }
try { I.innerHTML = PRINTJ.sprintf("I(%.11g, %d) = %+.11g", v, o, BESSEL.besseli(v, o)); } catch(e) { I.innerHTML = String(e); }
try { K.innerHTML = PRINTJ.sprintf("K(%.11g, %d) = %+.11g", v, o, BESSEL.besselk(v, o)); } catch(e) { K.innerHTML = String(e); }
}
/* Bind to relevant events */
if(O.addEventListener) {
O.addEventListener('keyup', update);
V.addEventListener('keyup', update);
J.addEventListener('change', update);
Y.addEventListener('change', update);
I.addEventListener('change', update);
K.addEventListener('change', update);
} else if(O.attachEvent) {
O.attachEvent('onkeyup', update);
V.attachEvent('onkeyup', update);
J.attachEvent('onchange', update);
Y.attachEvent('onchange', update);
I.attachEvent('onchange', update);
K.attachEvent('onchange', update);
} else {
O.oninput = update;
V.oninput = update;
J.onchange = update;
Y.onchange = update;
I.onchange = update;
K.onchange = update;
}
window.onload = function() { update(); };
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36810333-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</html>

42
misc/help.sh Executable file

@ -0,0 +1,42 @@
#!/bin/bash
# make_help.sh -- process listing of targets and special items in Makefile
# Copyright (C) 2016-present SheetJS
#
# usage in makefile: pipe the output of the following command:
# @grep -hE '(^[a-zA-Z_-][ a-zA-Z_-]*:.*?|^#[#*])' $(MAKEFILE_LIST)
#
# lines starting with "## " are treated as subtitles
# lines starting with "#* " are treated as plaintext comments
# multiple targets with "## " after the ":" are rendered as separate targets
# if the presumed default target is labeled, it will be assigned a unique color
awk '
BEGIN{recipes=0;}
!/#[#*] .*$/ {next;}
{multi=0; isrecipe=0;}
/^[^#]*:/ {isrecipe=1; ++recipes;}
/^[^ :]* .*:/ {multi=1}
multi==0 && isrecipe>0 { if(recipes > 1) print; else print $0, "[default]"; next}
isrecipe == 0 {print; next}
multi>0 {
k=split($0, msg, "##"); m=split($0, a, ":"); n=split(a[1], b, " ");
for(i=1; i<=n; ++i) print b[i] ":", "##" msg[2], (recipes==1 && i==1 ? "[default]" : "")
}
END {}
' | if [[ -t 1 ]]; then
awk '
BEGIN {FS = ":.*?## "}
{color=36}
/\[default\]/ {color=35}
NF==1 && /^##/ {color=34}
NF==1 && /^#\*/ {color=20; $1 = substr($1, 4)}
{printf "\033[" color "m%-20s\033[0m %s\n", $1, $2;}
END{}' -
else
awk '
BEGIN {FS = ":.*?## "}
/^#\* / {$1 = substr($1, 4)}
{printf "%-20s %s\n", $1, $2;}
END{}' -
fi

14
misc/spin.sh Executable file

@ -0,0 +1,14 @@
#!/bin/bash
# spin.sh -- show a spinner (for coverage test)
# Copyright (C) 2014-present SheetJS
wpid=$1
delay=1
str="|/-\\"
while [ $(ps -a|awk '$1=='$wpid' {print $1}') ]; do
t=${str#?}
printf " [%c]" "$str"
str=$t${str%"$t"}
sleep $delay
printf "\b\b\b\b"
done

@ -1,19 +1,28 @@
{
"name": "bessel",
"version": "0.2.0",
"version": "1.0.2",
"author": "SheetJS",
"description": "Bessel Functions in pure JS",
"keywords": ["bessel", "math", "specfun"],
"main": "bessel.js",
"repository": { "type": "git", "url": "https://github.com/SheetJS/bessel" },
"license": "MIT",
"description": "Pure-JS Bessel Functions",
"keywords": [ "bessel", "math", "specfun" ],
"main": "./bessel",
"dependencies": {
},
"devDependencies": {
"mocha":"~2.5.3",
"voc":"~1.0.0"
},
"repository": { "type":"git", "url":"git://github.com/SheetJS/bessel.git" },
"scripts": {
"test": "make test"
},
"dependencies": {
"voc":""
"config": {
"blanket": {
"pattern": "bessel.js"
}
},
"devDependencies": {
"mocha":""
}
"files": ["bessel.js", "LICENSE", "README.md"],
"homepage": "https://oss.sheetjs.com/bessel/",
"bugs": { "url": "https://github.com/SheetJS/bessel/issues" },
"license": "Apache-2.0",
"engines": { "node": ">=0.8" }
}

237
shim.js Normal file

@ -0,0 +1,237 @@
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
if (!Object.keys) {
Object.keys = (function () {
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;
return function (obj) {
if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object');
var result = [];
for (var prop in obj) {
if (hasOwnProperty.call(obj, prop)) result.push(prop);
}
if (hasDontEnumBug) {
for (var i=0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
}
}
return result;
};
})();
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
if (!Array.prototype.filter)
{
Array.prototype.filter = function(fun /*, thisp */)
{
"use strict";
if (this == null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in t)
{
var val = t[i]; // in case fun mutates this
if (fun.call(thisp, val, i, t))
res.push(val);
}
}
return res;
};
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, '');
};
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisArg */)
{
"use strict";
if (this === void 0 || this === null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")
throw new TypeError();
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++)
{
if (i in t)
fun.call(thisArg, t[i], i, t);
}
};
}
// Production steps of ECMA-262, Edition 5, 15.4.4.19
// Reference: http://es5.github.com/#x15.4.4.19
if (!Array.prototype.map) {
Array.prototype.map = function(callback, thisArg) {
var T, A, k;
if (this == null) {
throw new TypeError(" this is null or not defined");
}
// 1. Let O be the result of calling ToObject passing the |this| value as the argument.
var O = Object(this);
// 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
// 3. Let len be ToUint32(lenValue).
var len = O.length >>> 0;
// 4. If IsCallable(callback) is false, throw a TypeError exception.
// See: http://es5.github.com/#x9.11
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (thisArg) {
T = thisArg;
}
// 6. Let A be a new array created as if by the expression new Array(len) where Array is
// the standard built-in constructor with that name and len is the value of len.
A = new Array(len);
// 7. Let k be 0
k = 0;
// 8. Repeat, while k < len
while(k < len) {
var kValue, mappedValue;
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
// b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
// This step can be combined with c
// c. If kPresent is true, then
if (k in O) {
// i. Let kValue be the result of calling the Get internal method of O with argument Pk.
kValue = O[ k ];
// ii. Let mappedValue be the result of calling the Call internal method of callback
// with T as the this value and argument list containing kValue, k, and O.
mappedValue = callback.call(T, kValue, k, O);
// iii. Call the DefineOwnProperty internal method of A with arguments
// Pk, Property Descriptor {Value: mappedValue, : true, Enumerable: true, Configurable: true},
// and false.
// In browsers that support Object.defineProperty, use the following:
// Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true });
// For best browser support, use the following:
A[ k ] = mappedValue;
}
// d. Increase k by 1.
k++;
}
// 9. return A
return A;
};
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
if ( this === undefined || this === null ) {
throw new TypeError( '"this" is null or not defined' );
}
var length = this.length >>> 0; // Hack to convert object.length to a UInt32
fromIndex = +fromIndex || 0;
if (Math.abs(fromIndex) === Infinity) {
fromIndex = 0;
}
if (fromIndex < 0) {
fromIndex += length;
if (fromIndex < 0) {
fromIndex = 0;
}
}
for (;fromIndex < length; fromIndex++) {
if (this[fromIndex] === searchElement) {
return fromIndex;
}
}
return -1;
};
}
// Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
if (! Array.isArray) {
Array.isArray = function(obj) {
return Object.prototype.toString.call(obj) === "[object Array]";
};
}
// https://github.com/ttaubert/node-arraybuffer-slice
// (c) 2013 Tim Taubert <tim@timtaubert.de>
// arraybuffer-slice may be freely distributed under the MIT license.
"use strict";
if (typeof ArrayBuffer !== 'undefined' && !ArrayBuffer.prototype.slice) {
ArrayBuffer.prototype.slice = function (begin, end) {
begin = (begin|0) || 0;
var num = this.byteLength;
end = end === (void 0) ? num : (end|0);
// Handle negative values.
if (begin < 0) begin += num;
if (end < 0) end += num;
if (num === 0 || begin >= num || begin >= end) {
return new ArrayBuffer(0);
}
var length = Math.min(num - begin, end - begin);
var target = new ArrayBuffer(length);
var targetArray = new Uint8Array(target);
targetArray.set(new Uint8Array(this, begin, length));
return target;
};
}

@ -1,4 +0,0 @@
<script src="bessel.js"></script>
<script>
console.log(besselj(1,2));
</script>

142
test.js

@ -1,22 +1,124 @@
var assert = require('assert');
var bessel;
describe('When using bessel functions', function() {
before(function() {
bessel = require('./bessel');
});
it('It must load besseli', function() {
assert.equal(typeof bessel.besseli, 'function');
});
it('It must compute the Modified Bessel function at 1.5 with an order of 1 (0.981666)', function() {
assert(Math.floor((bessel.besseli(1.5, 1) - 0.981666) * 10e6) < 10);
});
it('It must compute the Bessel function at 1.9 with an order of 2 (0.329926)', function() {
assert(Math.floor((bessel.besselj(1.9, 2) - 0.329926) * 10e6) < 10);
});
it('It must compute the Modified Bessel function at 1.5 with an order of 1 (0.277388)', function() {
assert(Math.floor((bessel.besselk(1.5, 1) - 0.277388) * 10e6) < 10);
});
it('It must compute Weber\'s Bessel function at 2.5 with an order of 1 (0.145918)', function() {
assert(Math.floor((bessel.besselk(2.5, 1) - 0.981666) * 10e6) < 10);
/* vim: set ts=2: */
var X;
if(typeof require !== 'undefined') {
assert = require('assert');
describe('source',function(){
it('should load',function(){X=require('./');});
it('all bessel functions', function() {
assert.equal(typeof X.besseli, 'function');
assert.equal(typeof X.besselj, 'function');
assert.equal(typeof X.besselk, 'function');
assert.equal(typeof X.bessely, 'function');
});
});
} else { X = BESSEL; }
function approx(a, b, t) { return Math.abs((a - b) / (Math.abs(a) + Math.abs(b))) <= t; }
function chk(func, x, n, v, F, t) {
var V = func(x,n);
if(!approx(V, v, t) && v != V && !(isNaN(v) && isNaN(V))) throw new Error(F + "(" + x + "," + n + ") = " + V + " !~ " + v);
}
var funcs = ['besseli', 'besselj', 'besselk', 'bessely'];
var tests = {
'besseli': [
[1.5, 1, 0.981666],
[1.9, 2, 0.603272435],
[2.5, 1, 2.516716242]
],
'besselj': [
[1.5, 1, 0.557936508],
[1.9, 2, 0.329925829],
[2.5, 1, 0.497094103]
],
'besselk': [
[1.5, 1, 0.277388],
[1.9, 2, 0.296909301],
[2.5, 1, 0.073890816]
],
'bessely': [
[1.5, 1, -0.412308627],
[1.9, 2, -0.669878674],
[2.5, 1, 0.14591814]
] };
describe('correctness', function() {
funcs.forEach(function(F) { it(F, function() {
tests[F].forEach(function(t) { chk(X[F], t[0], t[1], t[2], F, 1e-6); });
});});
if(typeof require != 'undefined') {
var fs = require('fs');
it('excel', function() {
var xl = fs.readFileSync("test_files/excel.tsv", 'ascii').split("\n").map(function(l) { return l.split("\t");});
xl.forEach(function(l) { if(l.length < 6) return;
var x=Number(l[0]), n=Number(l[1]);
var i=Number(l[2]), j=Number(l[3]), k=Number(l[4]), y=Number(l[5]);
chk(X.besseli, x, n, i, 'besseli', 1e-4);
chk(X.besselj, x, n, j, 'besselj', 1e-4);
chk(X.besselk, x, n, k, 'besselk', 1e-4);
chk(X.bessely, x, n, y, 'bessely', 1e-4);
});
});
it('mma', function() {
var mma = fs.readFileSync("test_files/mma.tsv", 'ascii').split("\n").map(function(l) { return l.split("\t");});
mma.forEach(function(l) { if(l.length < 6) return;
var x=Number(l[0]), n=Number(l[1]);
var i=Number(l[2]), j=Number(l[3]), k=Number(l[4]), y=Number(l[5]);
chk(X.besseli, x, n, i, 'besseli', 1e-5);
chk(X.besselj, x, n, j, 'besselj', 1e-5);
chk(X.besselk, x, n, k, 'besselk', 1e-5);
chk(X.bessely, x, n, y, 'bessely', 1e-5);
});
});
}
});
var rand = [
0.3946086812775882, 3.946086812775882, 39.46086812775882,
0.03119419917289612, 0.3119419917289612, 3.119419917289612,
0.18311903629136062, 1.8311903629136062, 18.311903629136062,
0.5317681126599452, 5.317681126599452, 53.17681126599452,
0.37724541457032235, 3.7724541457032235, 37.724541457032235,
0.8287802926845655, 8.287802926845655, 82.87802926845655,
0.7197724866379658, 7.197724866379658, 71.97724866379658
];
describe('properties', function() {
var t = 1e-4;
it('limiting behavior', function() {
chk(X.besselj, 0, 0, 1, 'besselj', 1e-6);
chk(X.besseli, 0, 0, 1, 'besseli', 1e-6);
chk(X.besselk, 0, 0, Infinity, 'besselk', 1e-6);
chk(X.bessely, 0, 0, -Infinity, 'bessely', 1e-6);
for(var i = 1; i < 20; ++i) {
chk(X.besselj, 0, i, 0, 'besselj', 1e-6);
chk(X.besseli, 0, i, 0, 'besseli', 1e-6);
}
});
it('besselj', function() {
var F = "BESSELJ", f = X.besselj;
rand.forEach(function(r) {
for(var n = 0; n < 20; ++n) {
var pp = f( r, n), pn = f( r, -n), np = f(-r, n), nn = f(-r, -n);
if((n%2)) {
/* besselj odd if n is odd */
if(!approx(np, -pp, t)) throw new Error(F + " np[" + np + "] != -pp[" + (-pp) + "] (" + r + "," + n + ")");
if(!approx(nn, -pn, t)) throw new Error(F + " nn[" + nn + "] != -pn[" + (-pn) + "] (" + r + "," + n + ")");
/* asymmetric in n */
if(!approx(pn, -pp, t)) throw new Error(F + " pn[" + pn + "] != -pp[" + (-pp) + "] (" + r + "," + n + ")");
if(!approx(nn, -np, t)) throw new Error(F + " nn[" + nn + "] != -pn[" + (-pn) + "] (" + r + "," + n + ")");
} else {
/* besselj even if n is even */
if(!approx(np, pp, t)) throw new Error(F + " np[" + np + "] != pp[" + (pp) + "] (" + r + "," + n + ")");
if(!approx(nn, pn, t)) throw new Error(F + " nn[" + nn + "] != pn[" + (pn) + "] (" + r + "," + n + ")");
/* symmetric in n */
if(!approx(pn, pp, t)) throw new Error(F + " pn[" + pn + "] != pp[" + (pp) + "] (" + r + "," + n + ")");
if(!approx(nn, np, t)) throw new Error(F + " nn[" + nn + "] != pn[" + (pn) + "] (" + r + "," + n + ")");
}
}
});
});
});

60
test_files/excel.tsv Normal file

@ -0,0 +1,60 @@
0.5 1 0.257894303 0.242268458 1.656441128 -1.471472392
1 1 0.565159098 0.440050586 0.601907232 -0.781212821
1.5 1 0.981666428 0.557936508 0.277387804 -0.412308627
2 1 1.590636857 0.576724808 0.13986588 -0.107032432
2.5 1 2.516716242 0.497094103 0.073890816 0.145918138
3 1 3.953370217 0.339058958 0.040156431 0.324674424
3.5 1 6.205834932 0.137377527 0.022239393 0.410188417
4 1 9.759465157 -0.066043328 0.012483499 0.397925709
4.5 1 15.38922293 -0.231060432 0.007078095 0.300997321
5 1 24.33564185 -0.327579139 0.004044613 0.14786314
5.5 1 38.58816378 -0.341438216 0.002325569 -0.023758243
6 1 61.34193694 -0.276683859 0.00134392 -0.175010349
6.5 1 97.73501304 -0.153841304 0.000779894 -0.274091281
7 1 156.0390965 -0.004682826 0.000454182 -0.302667244
7.5 1 249.5843679 0.135248424 0.000265297 -0.25912852
8 1 399.8731348 0.234628387 0.000155369 -0.158060462
8.5 1 641.6198938 0.273115291 9.11973E-05 -0.02616868
9 1 1030.914709 0.245307412 5.3637E-05 0.104314575
9.5 1 1658.453068 0.161262274 3.1602E-05 0.203179899
10 1 2670.988321 0.04347225 1.86488E-05 0.249015424
0.5 2 0.031906148 0.030604023 7.550183547 -5.441370834
1 2 0.135747667 0.114903485 1.624838884 -1.650682613
1.5 2 0.337834621 0.232087679 0.583655974 -0.932193761
2 2 0.688948449 0.352834208 0.25375976 -0.617408098
2.5 2 1.276466159 0.446059058 0.121460207 -0.381335848
3 2 2.245212431 0.486091263 0.061510459 -0.160400399
3.5 2 3.832012072 0.458629185 0.032307122 0.045371436
4 2 6.422189499 0.364128143 0.017401426 0.215903599
4.5 2 10.64151731 0.217848984 0.009545677 0.328481596
5 2 17.50561501 0.046565119 0.005308944 0.367662879
5.5 2 28.66258571 -0.117315483 0.00298437 0.330841237
6 2 46.7870949 -0.242873213 0.001691968 0.229857908
6.5 2 76.22054669 -0.307430389 0.000965899 0.088906659
7 2 124.01131 -0.301417224 0.000554562 -0.0605266
7.5 2 201.6054825 -0.230273411 0.000319924 -0.186414216
8 2 327.5958389 -0.112993711 0.000185313 -0.263036605
8.5 2 532.1925545 0.022323169 0.000107716 -0.276362442
9 2 864.4962206 0.144846369 6.28006E-05 -0.226755682
9.5 2 1404.333008 0.2278787 3.67109E-05 -0.128435911
10 2 2281.518997 0.254630214 2.15098E-05 -0.005868083
0.5 3 0.002645112 0.00256373 62.0579095 -42.05949428
1 3 0.022168424 0.019563354 7.101262769 -5.821517632
1.5 3 0.080774114 0.060963951 1.833803735 -2.073541401
2 3 0.21273996 0.12894325 0.6473854 -1.127783765
2.5 3 0.474370413 0.216600403 0.268227146 -0.756055495
3 3 0.959753625 0.309062865 0.122170376 -0.538541623
3.5 3 1.826392593 0.386770113 0.059161818 -0.358335346
4 3 3.337275843 0.430171471 0.029884924 -0.18202211
4.5 3 5.930096274 0.424703973 0.015563141 -0.009013679
5 3 10.3311502 0.364831234 0.008291768 0.146267163
5.5 3 17.7426483 0.256117865 0.00449602 0.264370052
6 3 30.15054042 0.114768384 0.002471898 0.328248955
6.5 3 50.83005827 -0.035346628 0.001374294 0.328803071
7 3 85.17548647 -0.167555588 0.000771075 0.268080616
7.5 3 142.0614436 -0.25806091 0.000435923 0.159707605
8 3 236.0752263 -0.291125242 0.000248026 0.026542159
8.5 3 391.1763672 -0.26261027 0.000141887 -0.103884234
9 3 646.6942118 -0.180931248 8.15484E-05 -0.205094878
9.5 3 1067.155009 -0.065313348 4.70593E-05 -0.257258177
10 3 1758.380739 0.058379836 2.72527E-05 -0.251362657
1 0.5 1 0.257894303 0.242268458 1.656441128 -1.471472392
2 1 1 0.565159098 0.440050586 0.601907232 -0.781212821
3 1.5 1 0.981666428 0.557936508 0.277387804 -0.412308627
4 2 1 1.590636857 0.576724808 0.13986588 -0.107032432
5 2.5 1 2.516716242 0.497094103 0.073890816 0.145918138
6 3 1 3.953370217 0.339058958 0.040156431 0.324674424
7 3.5 1 6.205834932 0.137377527 0.022239393 0.410188417
8 4 1 9.759465157 -0.066043328 0.012483499 0.397925709
9 4.5 1 15.38922293 -0.231060432 0.007078095 0.300997321
10 5 1 24.33564185 -0.327579139 0.004044613 0.14786314
11 5.5 1 38.58816378 -0.341438216 0.002325569 -0.023758243
12 6 1 61.34193694 -0.276683859 0.00134392 -0.175010349
13 6.5 1 97.73501304 -0.153841304 0.000779894 -0.274091281
14 7 1 156.0390965 -0.004682826 0.000454182 -0.302667244
15 7.5 1 249.5843679 0.135248424 0.000265297 -0.25912852
16 8 1 399.8731348 0.234628387 0.000155369 -0.158060462
17 8.5 1 641.6198938 0.273115291 9.11973E-05 -0.02616868
18 9 1 1030.914709 0.245307412 5.3637E-05 0.104314575
19 9.5 1 1658.453068 0.161262274 3.1602E-05 0.203179899
20 10 1 2670.988321 0.04347225 1.86488E-05 0.249015424
21 0.5 2 0.031906148 0.030604023 7.550183547 -5.441370834
22 1 2 0.135747667 0.114903485 1.624838884 -1.650682613
23 1.5 2 0.337834621 0.232087679 0.583655974 -0.932193761
24 2 2 0.688948449 0.352834208 0.25375976 -0.617408098
25 2.5 2 1.276466159 0.446059058 0.121460207 -0.381335848
26 3 2 2.245212431 0.486091263 0.061510459 -0.160400399
27 3.5 2 3.832012072 0.458629185 0.032307122 0.045371436
28 4 2 6.422189499 0.364128143 0.017401426 0.215903599
29 4.5 2 10.64151731 0.217848984 0.009545677 0.328481596
30 5 2 17.50561501 0.046565119 0.005308944 0.367662879
31 5.5 2 28.66258571 -0.117315483 0.00298437 0.330841237
32 6 2 46.7870949 -0.242873213 0.001691968 0.229857908
33 6.5 2 76.22054669 -0.307430389 0.000965899 0.088906659
34 7 2 124.01131 -0.301417224 0.000554562 -0.0605266
35 7.5 2 201.6054825 -0.230273411 0.000319924 -0.186414216
36 8 2 327.5958389 -0.112993711 0.000185313 -0.263036605
37 8.5 2 532.1925545 0.022323169 0.000107716 -0.276362442
38 9 2 864.4962206 0.144846369 6.28006E-05 -0.226755682
39 9.5 2 1404.333008 0.2278787 3.67109E-05 -0.128435911
40 10 2 2281.518997 0.254630214 2.15098E-05 -0.005868083
41 0.5 3 0.002645112 0.00256373 62.0579095 -42.05949428
42 1 3 0.022168424 0.019563354 7.101262769 -5.821517632
43 1.5 3 0.080774114 0.060963951 1.833803735 -2.073541401
44 2 3 0.21273996 0.12894325 0.6473854 -1.127783765
45 2.5 3 0.474370413 0.216600403 0.268227146 -0.756055495
46 3 3 0.959753625 0.309062865 0.122170376 -0.538541623
47 3.5 3 1.826392593 0.386770113 0.059161818 -0.358335346
48 4 3 3.337275843 0.430171471 0.029884924 -0.18202211
49 4.5 3 5.930096274 0.424703973 0.015563141 -0.009013679
50 5 3 10.3311502 0.364831234 0.008291768 0.146267163
51 5.5 3 17.7426483 0.256117865 0.00449602 0.264370052
52 6 3 30.15054042 0.114768384 0.002471898 0.328248955
53 6.5 3 50.83005827 -0.035346628 0.001374294 0.328803071
54 7 3 85.17548647 -0.167555588 0.000771075 0.268080616
55 7.5 3 142.0614436 -0.25806091 0.000435923 0.159707605
56 8 3 236.0752263 -0.291125242 0.000248026 0.026542159
57 8.5 3 391.1763672 -0.26261027 0.000141887 -0.103884234
58 9 3 646.6942118 -0.180931248 8.15484E-05 -0.205094878
59 9.5 3 1067.155009 -0.065313348 4.70593E-05 -0.257258177
60 10 3 1758.380739 0.058379836 2.72527E-05 -0.251362657

60
test_files/mma.tsv Normal file

@ -0,0 +1,60 @@
0.5 1 0.2578943054 0.2422684577 1.65644112 -1.471472393
1 1 0.565159104 0.4400505857 0.6019072302 -0.7812128213
1.5 1 0.9816664286 0.5579365079 0.2773878005 -0.412308627
2 1 1.590636855 0.5767248078 0.1398658818 -0.1070324315
2.5 1 2.516716245 0.4970941025 0.07389081635 0.145918138
3 1 3.953370217 0.3390589585 0.04015643113 0.3246744248
3.5 1 6.205834922 0.1373775274 0.02223939293 0.4101884179
4 1 9.759465154 -0.06604332802 0.01248349889 0.3979257106
4.5 1 15.38922275 -0.2310604319 0.007078094909 0.3009973231
5 1 24.33564214 -0.3275791376 0.004044613445 0.1478631434
5.5 1 38.58816462 -0.3414382154 0.002325569009 -0.02375823896
6 1 61.34193678 -0.2766838581 0.001343919718 -0.1750103443
6.5 1 97.73501077 -0.1538413014 0.0007798943982 -0.274091274
7 1 156.0390929 -0.004682823482 0.0004541824869 -0.302667237
7.5 1 249.5843654 0.1352484276 0.0002652973901 -0.2591285105
8 1 399.8731368 0.2346363469 0.0001553692118 -0.1580604617
8.5 1 641.6199025 0.2731219637 0.00009119724775 -0.0261686794
9 1 1030.914723 0.2453117866 0.00005363701638 0.1043145752
9.5 1 1658.453078 0.1612644308 0.00003160203411 0.2031798994
10 1 2670.988304 0.04347274617 0.00001864877345 0.2490154242
0.5 2 0.03190614918 0.03060402346 7.550183551 -5.441370837
1 2 0.1357476698 0.1149034849 1.624838899 -1.650682607
1.5 2 0.3378346183 0.2320876721 0.5836559633 -0.9321937598
2 2 0.6889484477 0.3528340286 0.2537597546 -0.6174081042
2.5 2 1.276466148 0.4460590584 0.1214602063 -0.3813358492
3 2 2.245212441 0.4860912606 0.06151045847 -0.1604003935
3.5 2 3.832012048 0.4586291842 0.0323071217 0.04537143773
4 2 6.422189375 0.3641281459 0.01740142553 0.2159035946
4.5 2 10.6415173 0.2178489837 0.009545677203 0.3284815967
5 2 17.50561497 0.04656511628 0.005308943712 0.3676628826
5.5 2 28.66258529 -0.1173154816 0.002984370024 0.3308412333
6 2 46.78709472 -0.24287321 0.001691967567 0.2298579025
6.5 2 76.22054724 -0.3074303906 0.0009658992748 0.08890665832
7 2 124.0113105 -0.3014172201 0.0005545621667 -0.06052660947
7.5 2 201.6054807 -0.2302734105 0.0003199235871 -0.1864142223
8 2 327.5958315 -0.1129917204 0.0001853130082 -0.2630366048
8.5 2 532.1925382 0.02232473961 0.0001077157423 -0.2763624417
9 2 864.496194 0.1448473415 0.00006280064993 -0.2267556816
9.5 2 1404.332974 0.2278791542 0.00003671094477 -0.1284359105
10 2 2281.518968 0.2546303137 0.00002150981701 -0.005868082442
0.5 3 0.002645111969 0.002563729995 62.05790953 -42.0594943
1 3 0.02216842492 0.01956335398 7.101262825 -5.821517606
1.5 3 0.08077411302 0.06096395114 1.833803702 -2.073541399
2 3 0.2127399592 0.1289432495 0.6473853909 -1.127783777
2.5 3 0.4743704088 0.216600391 0.2682271464 -0.7560554968
3 3 0.9597536295 0.3090627223 0.1221703758 -0.5385416161
3.5 3 1.826392582 0.3867701117 0.05916181773 -0.3583353462
4 3 3.337275778 0.4301714739 0.02988492442 -0.182022116
4.5 3 5.930096266 0.424703973 0.01556314131 -0.009013681594
5 3 10.33115017 0.3648312306 0.008291768415 0.1462671627
5.5 3 17.74264804 0.2561178651 0.004496019935 0.264370045
6 3 30.1505403 0.1147683848 0.002471898096 0.328248946
6.5 3 50.83005863 -0.03534663129 0.001374293952 0.3288030637
7 3 85.17548684 -0.167555588 0.0007710751536 0.268080603
7.5 3 142.0614424 -0.2580609132 0.0004359233032 0.1597075919
8 3 236.075221 -0.2911322071 0.0002480257159 0.02654215932
8.5 3 391.1763552 -0.2626162039 0.0001418870088 -0.1038842343
9 3 646.6941919 -0.1809351903 0.00008154841635 -0.2050948781
9.5 3 1067.154983 -0.06531531322 0.00004705927401 -0.2572581775
10 3 1758.380717 0.05837937931 0.00002725270026 -0.2513626572
Can't render this file because it has a wrong number of fields in line 2.