• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / brs / #305

18 Jan 2024 09:05PM UTC coverage: 91.463% (+5.2%) from 86.214%
#305

push

TwitchBronBron
0.45.4

1796 of 2095 branches covered (85.73%)

Branch coverage included in aggregate %.

5275 of 5636 relevant lines covered (93.59%)

8947.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.63
/src/brsTypes/Int64.ts
1
import Long from "long";
139✔
2
import { BrsType, BrsBoolean } from "./";
139✔
3
import { BrsNumber, Numeric } from "./BrsNumber";
4
import { ValueKind, Comparable } from "./BrsType";
139✔
5
import { Float } from "./Float";
139✔
6
import { Double } from "./Double";
139✔
7
import { Boxable } from "./Boxing";
8
import { roLongInteger } from "./components/RoLongInteger";
139✔
9

10
export class Int64 implements Numeric, Comparable, Boxable {
139✔
11
    readonly kind = ValueKind.Int64;
268✔
12
    private readonly value: Long;
13

14
    getValue(): Long {
15
        return this.value;
272✔
16
    }
17

18
    /**
19
     * Creates a new BrightScript 64-bit integer value representing the provided `value`.
20
     * @param value the value to store in the BrightScript integer.
21
     */
22
    constructor(value: number | Long) {
23
        if (value instanceof Long) {
268✔
24
            this.value = value;
55✔
25
        } else {
26
            this.value = Long.fromNumber(Math.trunc(value));
213✔
27
        }
28
    }
29

30
    /**
31
     * Creates a new BrightScript 64-bit integer value representing the integer contained in
32
     * `asString`.
33
     * @param asString the string representation of the value to store in the BrightScript 64-bit
34
     *                 int. Will be rounded to the nearest 64-bit integer.
35
     * @returns a BrightScript 64-bit integer value representing `asString`.
36
     */
37
    static fromString(asString: string): Int64 {
38
        let radix = 10;
25✔
39

40
        if (asString.toLowerCase().startsWith("&h")) {
25✔
41
            radix = 16; // it's a hex literal!
2✔
42
            asString = asString.slice(2); // remove "&h" from the string representation
2✔
43
        }
44

45
        let i64 = new Int64(Long.fromString(asString, undefined, radix));
25✔
46
        return i64;
25✔
47
    }
48

49
    add(rhs: BrsNumber): BrsNumber {
50
        switch (rhs.kind) {
5✔
51
            case ValueKind.Int32:
52
            case ValueKind.Int64:
53
                return new Int64(this.getValue().add(rhs.getValue()));
3✔
54
            case ValueKind.Float:
55
                return new Float(this.getValue().toNumber() + rhs.getValue());
1✔
56
            case ValueKind.Double:
57
                return new Double(this.getValue().toNumber() + rhs.getValue());
1✔
58
        }
59
    }
60

61
    subtract(rhs: BrsNumber): BrsNumber {
62
        switch (rhs.kind) {
6✔
63
            case ValueKind.Int32:
64
            case ValueKind.Int64:
65
                return new Int64(this.getValue().subtract(rhs.getValue()));
4✔
66
            case ValueKind.Float:
67
                return new Float(this.getValue().toNumber() - rhs.getValue());
1✔
68
            case ValueKind.Double:
69
                return new Double(this.getValue().toNumber() - rhs.getValue());
1✔
70
        }
71
    }
72

73
    multiply(rhs: BrsNumber): BrsNumber {
74
        switch (rhs.kind) {
5✔
75
            case ValueKind.Int32:
76
            case ValueKind.Int64:
77
                return new Int64(this.getValue().multiply(rhs.getValue()));
2✔
78
            case ValueKind.Float:
79
                return new Float(this.getValue().toNumber() * rhs.getValue());
2✔
80
            case ValueKind.Double:
81
                return new Double(this.getValue().toNumber() * rhs.getValue());
1✔
82
        }
83
    }
84

85
    divide(rhs: BrsNumber): Float | Double {
86
        switch (rhs.kind) {
5✔
87
            case ValueKind.Int32:
88
            case ValueKind.Int64:
89
                return new Float(this.getValue().divide(rhs.getValue()).toNumber());
3✔
90
            case ValueKind.Float:
91
                return new Float(this.getValue().toNumber() / rhs.getValue());
1✔
92
            case ValueKind.Double:
93
                return new Double(this.getValue().toNumber() / rhs.getValue());
1✔
94
        }
95
    }
96

97
    modulo(rhs: BrsNumber): Int64 {
98
        switch (rhs.kind) {
5✔
99
            case ValueKind.Int32:
100
            case ValueKind.Int64:
101
                return new Int64(this.getValue().modulo(rhs.getValue()));
3✔
102
            case ValueKind.Float:
103
                return new Int64(this.getValue().toNumber() % rhs.getValue());
1✔
104
            case ValueKind.Double:
105
                return new Int64(this.getValue().toNumber() % rhs.getValue());
1✔
106
        }
107
    }
108

109
    intDivide(rhs: BrsNumber): Int64 {
110
        switch (rhs.kind) {
4✔
111
            case ValueKind.Int32:
112
            case ValueKind.Int64:
113
                return new Int64(this.getValue().divide(rhs.getValue()));
2✔
114
            case ValueKind.Float:
115
            case ValueKind.Double:
116
                return new Int64(Math.floor(this.getValue().toNumber() / rhs.getValue()));
2✔
117
        }
118
    }
119

120
    leftShift(rhs: BrsNumber): Int64 {
121
        switch (rhs.kind) {
×
122
            case ValueKind.Int32:
123
            case ValueKind.Float:
124
            case ValueKind.Double:
125
                return new Int64(this.getValue().toNumber() << Math.trunc(rhs.getValue()));
×
126
            case ValueKind.Int64:
127
                return new Int64(this.getValue().toNumber() << rhs.getValue().toNumber());
×
128
        }
129
    }
130

131
    rightShift(rhs: BrsNumber): Int64 {
132
        switch (rhs.kind) {
×
133
            case ValueKind.Int32:
134
            case ValueKind.Float:
135
            case ValueKind.Double:
136
                return new Int64(this.getValue().toNumber() >> Math.trunc(rhs.getValue()));
×
137
            case ValueKind.Int64:
138
                return new Int64(this.getValue().toNumber() >> rhs.getValue().toNumber());
×
139
        }
140
    }
141

142
    pow(exponent: BrsNumber): BrsNumber {
143
        switch (exponent.kind) {
7✔
144
            case ValueKind.Int32:
145
                return new Int64(Math.pow(this.getValue().toNumber(), exponent.getValue()));
1✔
146
            case ValueKind.Float:
147
                return new Float(Math.pow(this.getValue().toNumber(), exponent.getValue()));
1✔
148
            case ValueKind.Double:
149
                return new Double(Math.pow(this.getValue().toNumber(), exponent.getValue()));
1✔
150
            case ValueKind.Int64:
151
                return new Int64(
4✔
152
                    Math.pow(this.getValue().toNumber(), exponent.getValue().toNumber())
153
                );
154
        }
155
    }
156

157
    and(rhs: BrsNumber): BrsNumber {
158
        switch (rhs.kind) {
7✔
159
            case ValueKind.Int32:
160
            case ValueKind.Int64:
161
            case ValueKind.Float:
162
            case ValueKind.Double:
163
                return new Int64(this.getValue().and(rhs.getValue()));
7✔
164
        }
165
    }
166

167
    or(rhs: BrsNumber): BrsNumber {
168
        switch (rhs.kind) {
7✔
169
            case ValueKind.Int32:
170
            case ValueKind.Int64:
171
            case ValueKind.Float:
172
            case ValueKind.Double:
173
                return new Int64(this.getValue().or(rhs.getValue()));
7✔
174
        }
175
    }
176

177
    lessThan(other: BrsType): BrsBoolean {
178
        switch (other.kind) {
19✔
179
            case ValueKind.Int32:
180
            case ValueKind.Int64:
181
                return BrsBoolean.from(this.getValue().lessThan(other.getValue()));
12✔
182
            case ValueKind.Float:
183
                return new Float(this.getValue().toNumber()).lessThan(other);
2✔
184
            case ValueKind.Double:
185
                return new Double(this.getValue().toNumber()).lessThan(other);
2✔
186
            default:
187
                return BrsBoolean.False;
3✔
188
        }
189
    }
190

191
    greaterThan(other: BrsType): BrsBoolean {
192
        switch (other.kind) {
19✔
193
            case ValueKind.Int32:
194
            case ValueKind.Int64:
195
                return BrsBoolean.from(this.getValue().greaterThan(other.getValue()));
12✔
196
            case ValueKind.Float:
197
                return new Float(this.getValue().toNumber()).greaterThan(other);
2✔
198
            case ValueKind.Double:
199
                return new Double(this.getValue().toNumber()).greaterThan(other);
2✔
200
            default:
201
                return BrsBoolean.False;
3✔
202
        }
203
    }
204

205
    equalTo(other: BrsType): BrsBoolean {
206
        switch (other.kind) {
27✔
207
            case ValueKind.Int32:
208
            case ValueKind.Int64:
209
                return BrsBoolean.from(this.getValue().equals(other.getValue()));
18✔
210
            case ValueKind.Float:
211
                return new Float(this.getValue().toNumber()).equalTo(other);
2✔
212
            case ValueKind.Double:
213
                return new Double(this.getValue().toNumber()).equalTo(other);
2✔
214
            default:
215
                return BrsBoolean.False;
5✔
216
        }
217
    }
218

219
    toString(parent?: BrsType): string {
220
        return this.value.toString();
27✔
221
    }
222

223
    box() {
224
        return new roLongInteger(this);
16✔
225
    }
226
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc