smath 1.12.0 → 1.13.0
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/dist/bin.js +33 -27
- package/dist/index.js +550 -541
- package/package.json +3 -3
- package/types/index.d.ts +357 -351
package/types/index.d.ts
CHANGED
|
@@ -3,357 +3,363 @@
|
|
|
3
3
|
* Small math function library
|
|
4
4
|
*
|
|
5
5
|
* 
|
|
6
|
+
* 
|
|
6
7
|
*/
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* Check if two numbers are approximately equal with a maximum abolute error.
|
|
10
|
+
* @param a Any number
|
|
11
|
+
* @param b Any number
|
|
12
|
+
* @param epsilon Maximum absolute error
|
|
13
|
+
* @returns True if `a` is approximately `b`
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* const b1 = SMath.approx(1 / 3, 0.33, 1e-6), // false
|
|
17
|
+
* b2 = SMath.approx(1 / 3, 0.33, 1e-2); // true
|
|
18
|
+
* ```
|
|
10
19
|
*/
|
|
11
|
-
export declare
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
den: number;
|
|
358
|
-
};
|
|
359
|
-
}
|
|
20
|
+
export declare function approx(a: number, b: number, epsilon?: number): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Clamp a number within a range.
|
|
23
|
+
* @param n The number to clamp
|
|
24
|
+
* @param min The minimum value of the range
|
|
25
|
+
* @param max The maximum value of the range
|
|
26
|
+
* @returns A clamped number
|
|
27
|
+
* @example
|
|
28
|
+
* ```js
|
|
29
|
+
* const n1 = SMath.clamp(5, 0, 10), // 5
|
|
30
|
+
* n2 = SMath.clamp(-2, 0, 10); // 0
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function clamp(n: number, min: number, max: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* Normalize the number `n` from the range `min, max` to the range `0, 1`
|
|
36
|
+
* @param n The number to normalize
|
|
37
|
+
* @param min The minimum value in the range
|
|
38
|
+
* @param max The maximum value in the range
|
|
39
|
+
* @returns A normalized value
|
|
40
|
+
* @example
|
|
41
|
+
* ```js
|
|
42
|
+
* const y = SMath.normalize(18, 9, 99); // 0.1
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function normalize(n: number, min: number, max: number): number;
|
|
46
|
+
/**
|
|
47
|
+
* Expand a normalized number `n` to the range `min, max`
|
|
48
|
+
* @param n A normalized number
|
|
49
|
+
* @param min The minimum value in the range
|
|
50
|
+
* @param max The maximum value in the range
|
|
51
|
+
* @returns A value within the number range
|
|
52
|
+
* @example
|
|
53
|
+
* ```js
|
|
54
|
+
* const y = SMath.expand(0.25, 4, 6); // 4.5
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function expand(n: number, min: number, max: number): number;
|
|
58
|
+
/**
|
|
59
|
+
* Translate a number `n` from the range `min1, max1` to the range `min2, max2`
|
|
60
|
+
* @param n The number to translate
|
|
61
|
+
* @param min1 The minimum value from the initial range
|
|
62
|
+
* @param max1 The maximum value from the initial range
|
|
63
|
+
* @param min2 The minimum value for the final range
|
|
64
|
+
* @param max2 The maximum value for the final range
|
|
65
|
+
* @returns A translated number in the final range
|
|
66
|
+
* @example
|
|
67
|
+
* ```js
|
|
68
|
+
* const C = 20,
|
|
69
|
+
* F = SMath.translate(C, 0, 100, 32, 212); // 68
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function translate(n: number, min1: number, max1: number, min2: number, max2: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* Generate an array of linearly spaced numbers.
|
|
75
|
+
* @param min The initial value of the linear space
|
|
76
|
+
* @param max The final value of the linear space
|
|
77
|
+
* @param count The number of values in the space
|
|
78
|
+
* @returns The linear space as an array of numbers
|
|
79
|
+
* @example
|
|
80
|
+
* ```js
|
|
81
|
+
* const space = SMath.linspace(1, 5, 6);
|
|
82
|
+
* // [ 1, 1.8, 2.6, 3.4, 4.2, 5 ]
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function linspace(min: number, max: number, count: number): Array<number>;
|
|
86
|
+
/**
|
|
87
|
+
* Generate an array of logarithmically spaced numbers.
|
|
88
|
+
* @param min The initial magnitude of the space
|
|
89
|
+
* @param max The final magnitude of the space
|
|
90
|
+
* @param count The number of values in the space
|
|
91
|
+
* @returns The logarithmic space as an array of numbers
|
|
92
|
+
* @example
|
|
93
|
+
* ```js
|
|
94
|
+
* const space = SMath.logspace(0, 2, 5);
|
|
95
|
+
* // [ 1, 3.2, 10, 31.6, 100 ]
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function logspace(min: number, max: number, count: number): Array<number>;
|
|
99
|
+
/**
|
|
100
|
+
* Compute the factorial of `n`.
|
|
101
|
+
* @param n Any positive integer
|
|
102
|
+
* @returns `n!`
|
|
103
|
+
* @example
|
|
104
|
+
* ```js
|
|
105
|
+
* const y = SMath.factorial(5); // 120
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function factorial(n: number): number;
|
|
109
|
+
/**
|
|
110
|
+
* Factorize `n` into its prime factors.
|
|
111
|
+
* @param n Any positive integer
|
|
112
|
+
* @returns The array of prime factors
|
|
113
|
+
* @example
|
|
114
|
+
* ```js
|
|
115
|
+
* const y = SMath.factors(12); // [ 2, 2, 3 ]
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function factors(n: number): Array<number>;
|
|
119
|
+
/**
|
|
120
|
+
* Round a number to the nearest multiple of an arbitrary
|
|
121
|
+
* base. Does not round when the base is set to zero.
|
|
122
|
+
* @param n Any number to round
|
|
123
|
+
* @param base Any base to round to
|
|
124
|
+
* @returns `n` rounded to the nearest multiple of `base`
|
|
125
|
+
* @example
|
|
126
|
+
* ```js
|
|
127
|
+
* const y = SMath.round2(Math.PI, 0.2); // 3.2
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export declare function round2(n: number, base: number): number;
|
|
131
|
+
/**
|
|
132
|
+
* Calculate the relative normalized error or deviation from any
|
|
133
|
+
* value to an accepted value. An error of 0 indicates that the
|
|
134
|
+
* two values are identical. An error of -0.1 indicates that the
|
|
135
|
+
* experimental value is 10% smaller than (90% of) the accepted
|
|
136
|
+
* value. An error of 1.0 indicates that the experimental value
|
|
137
|
+
* is 100% greater (or twice the size) of the accepted value.
|
|
138
|
+
* @param experimental The value observed or produced by a test
|
|
139
|
+
* @param actual The accepted or theoretical value
|
|
140
|
+
* @returns The relative (normalized) error
|
|
141
|
+
* @example
|
|
142
|
+
* ```js
|
|
143
|
+
* const e = SMath.error(22.5, 25); // -0.1
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export declare function error(experimental: number, actual: number): number;
|
|
147
|
+
/**
|
|
148
|
+
* Add up all the inputs.
|
|
149
|
+
* If none are present, returns 0.
|
|
150
|
+
* @param data An array of numeric inputs
|
|
151
|
+
* @returns The sum total
|
|
152
|
+
* @example
|
|
153
|
+
* ```js
|
|
154
|
+
* const y = SMath.sum([1, 2, 3]); // 6
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function sum(data: Array<number>): number;
|
|
158
|
+
/**
|
|
159
|
+
* Multiply all the inputs.
|
|
160
|
+
* If none are present, returns 1.
|
|
161
|
+
* @param data An array of numeric inputs
|
|
162
|
+
* @returns The product
|
|
163
|
+
* @example
|
|
164
|
+
* ```js
|
|
165
|
+
* const y = SMath.prod([2, 2, 3, 5]); // 60
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function prod(data: Array<number>): number;
|
|
169
|
+
/**
|
|
170
|
+
* Compute the average, or mean, of a set of numbers.
|
|
171
|
+
* @param data An array of numeric inputs
|
|
172
|
+
* @returns The average, or mean
|
|
173
|
+
* @example
|
|
174
|
+
* ```js
|
|
175
|
+
* const y = SMath.avg([1, 2, 4, 4]); // 2.75
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare function avg(data: Array<number>): number;
|
|
179
|
+
/**
|
|
180
|
+
* Compute the median of a set of numbers.
|
|
181
|
+
* @param data An array of numeric inputs
|
|
182
|
+
* @returns The median of the dataset
|
|
183
|
+
* @example
|
|
184
|
+
* ```js
|
|
185
|
+
* const y = SMath.median([2, 5, 3, 1]); // 2.5
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export declare function median(data: Array<number>): number;
|
|
189
|
+
/**
|
|
190
|
+
* Compute the variance of a **complete population**.
|
|
191
|
+
* @param data An array of numeric inputs
|
|
192
|
+
* @returns The population variance
|
|
193
|
+
* @example
|
|
194
|
+
* ```js
|
|
195
|
+
* const y = SMath.varp([1, 2, 4, 4]); // 1.6875
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export declare function varp(data: Array<number>): number;
|
|
199
|
+
/**
|
|
200
|
+
* Compute the variance of a **sample**.
|
|
201
|
+
* @param data An array of numeric inputs
|
|
202
|
+
* @returns The sample variance
|
|
203
|
+
* @example
|
|
204
|
+
* ```js
|
|
205
|
+
* const y = SMath.vars([1, 2, 4, 4]); // 2.25
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare function vars(data: Array<number>): number;
|
|
209
|
+
/**
|
|
210
|
+
* Compute the standard deviation of a **complete population**.
|
|
211
|
+
* @param data An array of numeric inputs
|
|
212
|
+
* @returns The population standard deviation
|
|
213
|
+
* @example
|
|
214
|
+
* ```js
|
|
215
|
+
* const y = SMath.stdevp([1, 2, 3, 4]); // 1.118...
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
export declare function stdevp(data: Array<number>): number;
|
|
219
|
+
/**
|
|
220
|
+
* Compute the standard deviation of a **sample**.
|
|
221
|
+
* @param data An array of numeric inputs
|
|
222
|
+
* @returns The sample standard deviation
|
|
223
|
+
* @example
|
|
224
|
+
* ```js
|
|
225
|
+
* const y = SMath.stdevs([1, 2, 3, 4]); // 1.29...
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export declare function stdevs(data: Array<number>): number;
|
|
229
|
+
/**
|
|
230
|
+
* Generate a uniformly-distributed floating-point number within the range.
|
|
231
|
+
* @param min The minimum bound
|
|
232
|
+
* @param max The maximum bound
|
|
233
|
+
* @returns A random float within the range
|
|
234
|
+
* @example
|
|
235
|
+
* ```js
|
|
236
|
+
* const y = SMath.runif(-2, 2); // 0.376...
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export declare function runif(min: number, max: number): number;
|
|
240
|
+
/**
|
|
241
|
+
* Generate a uniformly-distributed integer within the range.
|
|
242
|
+
* @param min The minimum bound (inclusive)
|
|
243
|
+
* @param max The maximum bound (inclusive)
|
|
244
|
+
* @returns A random integer within the range
|
|
245
|
+
* @example
|
|
246
|
+
* ```js
|
|
247
|
+
* const y = SMath.rint(-4, 3); // -4
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
export declare function rint(min: number, max: number): number;
|
|
251
|
+
/**
|
|
252
|
+
* Generate a normally-distributed floating-point number.
|
|
253
|
+
* @param mean The mean of the population distribution
|
|
254
|
+
* @param stdev The standard deviation of the population
|
|
255
|
+
* @returns A random float
|
|
256
|
+
* @example
|
|
257
|
+
* ```js
|
|
258
|
+
* const y = SMath.rnorm(2, 3); // 1.627...
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export declare function rnorm(mean?: number, stdev?: number): number;
|
|
262
|
+
/**
|
|
263
|
+
* Generate a population of normally-distributed floating-point numbers.
|
|
264
|
+
* @param count The number of values to generate
|
|
265
|
+
* @param mean The mean of the population distribution
|
|
266
|
+
* @param stdev The standard deviation of the population
|
|
267
|
+
* @returns A population of random floats
|
|
268
|
+
* @example
|
|
269
|
+
* ```js
|
|
270
|
+
* const dataset = SMath.rdist(3); // [ 1.051..., -0.779..., -2.254... ]
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
export declare function rdist(count: number, mean?: number, stdev?: number): Array<number>;
|
|
274
|
+
/**
|
|
275
|
+
* Randomize an array of arbitrary elements.
|
|
276
|
+
* @param stack An array of arbitrary elements
|
|
277
|
+
* @returns The `stack` array in a random order
|
|
278
|
+
* @example
|
|
279
|
+
* ```js
|
|
280
|
+
* const shuffled = SMath.shuffle(['a', 'b', 'c']); // [ 'c', 'a', 'b' ]
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export declare function shuffle<T>(stack: Array<T>): Array<T>;
|
|
284
|
+
/**
|
|
285
|
+
* Take the limit of a function. A return value of `NaN` indicates
|
|
286
|
+
* that no limit exists either due to a discontinuity or imaginary value.
|
|
287
|
+
* @param f Function `f(x)`
|
|
288
|
+
* @param x The x-value where to take the limit
|
|
289
|
+
* @param h The approach distance
|
|
290
|
+
* @param discontinuity_cutoff The discontinuity cutoff
|
|
291
|
+
* @returns `lim(f(x->x))`
|
|
292
|
+
* @example
|
|
293
|
+
* ```js
|
|
294
|
+
* const y = SMath.lim(Math.log, 0); // -Infinity
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
export declare function lim(f: (x: number) => number, x: number, h?: number, discontinuity_cutoff?: number): number;
|
|
298
|
+
/**
|
|
299
|
+
* Take the derivative of a function.
|
|
300
|
+
* @param f Function `f(x)`
|
|
301
|
+
* @param x The x-value where to evaluate the derivative
|
|
302
|
+
* @param h Small step value
|
|
303
|
+
* @returns `f'(x)`
|
|
304
|
+
* @example
|
|
305
|
+
* ```js
|
|
306
|
+
* const y = SMath.differentiate(x => 3 * x ** 2, 2); // 12
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
export declare function differentiate(f: (x: number) => number, x: number, h?: number): number;
|
|
310
|
+
/**
|
|
311
|
+
* Compute the definite integral of a function.
|
|
312
|
+
* @param f Function `f(x)`
|
|
313
|
+
* @param a The miminum integral bound
|
|
314
|
+
* @param b The maximum integral bound
|
|
315
|
+
* @param Ndx The number of rectangles to compute
|
|
316
|
+
* @returns `F(b)-F(a)`
|
|
317
|
+
* @example
|
|
318
|
+
* ```js
|
|
319
|
+
* const y = SMath.integrate(x => 3 * x ** 2, 1, 2); // 7
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
export declare function integrate(f: (x: number) => number, a: number, b: number, Ndx?: number): number;
|
|
323
|
+
/**
|
|
324
|
+
* Convert an arbitrary decimal number into a simplified fraction (or ratio).
|
|
325
|
+
* See `mixed()` for instructions on how to break out the whole number part.
|
|
326
|
+
* @param n The decimal number to convert
|
|
327
|
+
* @param epsilon Maximum absolute error
|
|
328
|
+
* @returns An object containing the fraction's numerator and denominator
|
|
329
|
+
* @example
|
|
330
|
+
* ```js
|
|
331
|
+
* const frac = SMath.rat(0.625); // { num: 5, den: 8 }
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
export declare function rat(n: number, epsilon?: number): {
|
|
335
|
+
num: number;
|
|
336
|
+
den: number;
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Convert an arbitrary decimal number into a simplified fraction, after
|
|
340
|
+
* breaking out the whole number part first. See `rat()` for keeping the
|
|
341
|
+
* number as a ratio without separating the whole number part.
|
|
342
|
+
* @param n A decimal number to convert
|
|
343
|
+
* @param epsilon Maximum absolute error
|
|
344
|
+
* @returns An object containing the whole part and fraction numerator and denominator
|
|
345
|
+
* @example
|
|
346
|
+
* ```js
|
|
347
|
+
* const frac = SMath.mixed(-8 / 6); // { whole: -1, num: 1, den: 3 }
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
export declare function mixed(n: number, epsilon?: number): {
|
|
351
|
+
whole: number;
|
|
352
|
+
num: number;
|
|
353
|
+
den: number;
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Convert any number to its hexadecimal equivalent.
|
|
357
|
+
* @param n A decimal number to convert
|
|
358
|
+
* @param length The minimum number of digits to show
|
|
359
|
+
* @returns The number `n` converted to hexadecimal
|
|
360
|
+
* @example
|
|
361
|
+
* ```js
|
|
362
|
+
* const hex = SMath.toHex(10, 2); // '0A'
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
export declare function toHex(n: number, length?: number): string;
|