@sc-voice/tools 3.2.0 → 3.3.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/index.mjs +2 -0
- package/package.json +1 -1
- package/src/math/interval.mjs +84 -0
- package/src/text/unicode.mjs +3 -0
package/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Unicode } from '../text/unicode.mjs';
|
|
2
|
+
|
|
3
|
+
export class Interval {
|
|
4
|
+
constructor(a, b) {
|
|
5
|
+
const msg = 'i6l.ctor';
|
|
6
|
+
let hi = null;
|
|
7
|
+
let lo = null;
|
|
8
|
+
const dbg = 0;
|
|
9
|
+
|
|
10
|
+
let an = typeof a === 'number' && !Number.isNaN(a);
|
|
11
|
+
let bn = typeof b === 'number' && !Number.isNaN(b);
|
|
12
|
+
|
|
13
|
+
if (an && bn) {
|
|
14
|
+
dbg && console.log(msg, 'an bn');
|
|
15
|
+
lo = a;
|
|
16
|
+
hi = b;
|
|
17
|
+
this.isClosed = true;
|
|
18
|
+
} else if (an) {
|
|
19
|
+
dbg && console.log(msg, 'an');
|
|
20
|
+
lo = a;
|
|
21
|
+
hi = Interval.INFINITY;
|
|
22
|
+
this.isClosed = false;
|
|
23
|
+
} else if (bn) {
|
|
24
|
+
dbg && console.log(msg, 'bn');
|
|
25
|
+
lo = Interval.INFINITY;
|
|
26
|
+
hi = b;
|
|
27
|
+
this.isClosed = false;
|
|
28
|
+
} else {
|
|
29
|
+
dbg && console.log(msg, '!an !bn');
|
|
30
|
+
this.isClosed = false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Object.defineProperty(this, 'lo', { value: lo });
|
|
34
|
+
Object.defineProperty(this, 'hi', { value: hi });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static get INFINITY() {
|
|
38
|
+
return Unicode.INFINITY;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get isEmpty() {
|
|
42
|
+
if (this.lo === null && this.hi === null) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (
|
|
46
|
+
this.lo === Interval.INFINITY ||
|
|
47
|
+
this.hi === Interval.INFINITY
|
|
48
|
+
) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return this.hi < this.lo;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get infimum() {
|
|
55
|
+
return this.lo === Interval.INFINITY
|
|
56
|
+
? '-' + Interval.INFINITY
|
|
57
|
+
: this.lo;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get supremum() {
|
|
61
|
+
return this.hi === Interval.INFINITY
|
|
62
|
+
? '+' + Interval.INFINITY
|
|
63
|
+
: this.hi;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
contains(num) {
|
|
67
|
+
if (typeof num !== 'number' || Number.isNaN(num)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
let { lo, hi } = this;
|
|
71
|
+
if (lo === Interval.INFINITY) {
|
|
72
|
+
throw new Error(`${msg}TBD`);
|
|
73
|
+
}
|
|
74
|
+
if (hi === Interval.INFINITY) {
|
|
75
|
+
throw new Error(`${msg}TBD`);
|
|
76
|
+
}
|
|
77
|
+
if (lo < num && num < hi) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
if (num < lo || hi < num) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|