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