@stdlib/math-iter-sequences-continued-fraction 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +481 -0
- package/NOTICE +1 -0
- package/README.md +384 -0
- package/docs/img/equation_continued_fraction.svg +82 -0
- package/docs/img/equation_simple_continued_fraction.svg +69 -0
- package/docs/img/equation_simple_continued_fraction_convergents.svg +100 -0
- package/docs/repl.txt +77 -0
- package/docs/types/index.d.ts +87 -0
- package/docs/types/test.ts +98 -0
- package/lib/index.js +54 -0
- package/lib/main.js +349 -0
- package/lib/validate.js +89 -0
- package/package.json +95 -0
package/lib/validate.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
|
|
24
|
+
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
25
|
+
var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;
|
|
26
|
+
var isFinite = require( '@stdlib/assert-is-finite' ).isPrimitive; // eslint-disable-line stdlib/no-redeclare
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// VARIABLES //
|
|
30
|
+
|
|
31
|
+
var returns = [
|
|
32
|
+
'terms',
|
|
33
|
+
'convergents',
|
|
34
|
+
'*'
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// MAIN //
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Validates function options.
|
|
42
|
+
*
|
|
43
|
+
* @private
|
|
44
|
+
* @param {Object} opts - destination object
|
|
45
|
+
* @param {Options} options - function options
|
|
46
|
+
* @param {NonNegativeInteger} [options.iter] - maximum number of iterations
|
|
47
|
+
* @param {PositiveNumber} [options.tol] - tolerance at which to terminate further evaluation of the continued fraction
|
|
48
|
+
* @param {string} [options.returns] - specifies the type of result to return (must be one of `'terms'`, `'convergents'`, or `'*'`)
|
|
49
|
+
* @returns {(Error|null)} null or an error object
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* var opts = {};
|
|
53
|
+
* var options = {
|
|
54
|
+
* 'iter': 50
|
|
55
|
+
* };
|
|
56
|
+
* var err = validate( opts, options );
|
|
57
|
+
* if ( err ) {
|
|
58
|
+
* throw err;
|
|
59
|
+
* }
|
|
60
|
+
*/
|
|
61
|
+
function validate( opts, options ) {
|
|
62
|
+
if ( !isPlainObject( options ) ) {
|
|
63
|
+
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
|
|
64
|
+
}
|
|
65
|
+
if ( hasOwnProp( options, 'iter' ) ) {
|
|
66
|
+
opts.iter = options.iter;
|
|
67
|
+
if ( !isNonNegativeInteger( options.iter ) ) {
|
|
68
|
+
return new TypeError( 'invalid option. `iter` option must be a nonnegative integer. Option: `' + options.iter + '`.' );
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if ( hasOwnProp( options, 'tol' ) ) {
|
|
72
|
+
opts.tol = options.tol;
|
|
73
|
+
if ( !isFinite( options.tol ) || options.tol <= 0.0 ) {
|
|
74
|
+
return new TypeError( 'invalid option. `tol` option must be a positive finite number. Option: `' + options.tol + '`.' );
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if ( hasOwnProp( options, 'returns' ) ) {
|
|
78
|
+
opts.returns = options.returns;
|
|
79
|
+
if ( returns.indexOf( options.returns ) === -1 ) {
|
|
80
|
+
return new TypeError( 'invalid option. `returns` option must be one of the following: '+returns.join( ', ' )+'. Option: `' + options.returns + '`.' );
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
// EXPORTS //
|
|
88
|
+
|
|
89
|
+
module.exports = validate;
|
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/math-iter-sequences-continued-fraction",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Create an iterator which generates a list of all continued fraction terms which can be obtained given the precision of a provided number.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"benchmark": "./benchmark",
|
|
19
|
+
"doc": "./docs",
|
|
20
|
+
"example": "./examples",
|
|
21
|
+
"lib": "./lib",
|
|
22
|
+
"test": "./test"
|
|
23
|
+
},
|
|
24
|
+
"types": "./docs/types",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "make test",
|
|
27
|
+
"test-cov": "make test-cov",
|
|
28
|
+
"examples": "make examples",
|
|
29
|
+
"benchmark": "make benchmark"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://stdlib.io",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git://github.com/stdlib-js/math-iter-sequences-continued-fraction.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@stdlib/assert-has-own-property": "^0.0.x",
|
|
41
|
+
"@stdlib/assert-is-finite": "^0.0.x",
|
|
42
|
+
"@stdlib/assert-is-nonnegative-integer": "^0.0.x",
|
|
43
|
+
"@stdlib/assert-is-plain-object": "^0.0.x",
|
|
44
|
+
"@stdlib/constants-float64-eps": "^0.0.x",
|
|
45
|
+
"@stdlib/math-base-special-abs": "^0.0.x",
|
|
46
|
+
"@stdlib/math-base-special-floor": "^0.0.x",
|
|
47
|
+
"@stdlib/symbol-iterator": "^0.0.x",
|
|
48
|
+
"@stdlib/types": "^0.0.x",
|
|
49
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x",
|
|
50
|
+
"@stdlib/utils-fifo": "^0.0.x"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@stdlib/assert-is-array": "^0.0.x",
|
|
54
|
+
"@stdlib/assert-is-iterator-like": "^0.0.x",
|
|
55
|
+
"@stdlib/bench": "^0.0.x",
|
|
56
|
+
"@stdlib/constants-float64-pi": "^0.0.x",
|
|
57
|
+
"@stdlib/math-base-assert-is-nan": "^0.0.x",
|
|
58
|
+
"proxyquire": "^2.0.0",
|
|
59
|
+
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
60
|
+
"istanbul": "^0.4.1",
|
|
61
|
+
"tap-spec": "5.x.x"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=0.10.0",
|
|
65
|
+
"npm": ">2.7.0"
|
|
66
|
+
},
|
|
67
|
+
"os": [
|
|
68
|
+
"aix",
|
|
69
|
+
"darwin",
|
|
70
|
+
"freebsd",
|
|
71
|
+
"linux",
|
|
72
|
+
"macos",
|
|
73
|
+
"openbsd",
|
|
74
|
+
"sunos",
|
|
75
|
+
"win32",
|
|
76
|
+
"windows"
|
|
77
|
+
],
|
|
78
|
+
"keywords": [
|
|
79
|
+
"stdlib",
|
|
80
|
+
"stdmath",
|
|
81
|
+
"mathematics",
|
|
82
|
+
"math",
|
|
83
|
+
"continued",
|
|
84
|
+
"fraction",
|
|
85
|
+
"sequence",
|
|
86
|
+
"iterator",
|
|
87
|
+
"iterate",
|
|
88
|
+
"iteration",
|
|
89
|
+
"iter"
|
|
90
|
+
],
|
|
91
|
+
"funding": {
|
|
92
|
+
"type": "patreon",
|
|
93
|
+
"url": "https://www.patreon.com/athan"
|
|
94
|
+
}
|
|
95
|
+
}
|