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