Skip to content

Commit d0f8540

Browse files
committed
refactor - NSS - metaoperators, illion, exponentials, normalization
Added .pause for pausing the progress bar animations as if halted.
1 parent f5e8ea1 commit d0f8540

2 files changed

Lines changed: 94 additions & 18 deletions

File tree

docs/platforms/garrysmod/libraries/nss.md

Lines changed: 84 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,31 @@ Big-integer helper built on 32-bit words for arbitrary-size numeric storage, con
88
Static constructors and coercion helpers exposed directly on the `nss` class.
99

1010
- `#!ts nss.fromNumber(num: number): nss.object`\
11-
Builds an NSS value from a Lua number.
11+
Builds an NSS value from a Lua number.\
12+
Throws if `num` is `NaN`, `+inf`, or `-inf`.
1213

1314
- `#!ts nss.fromBinary(str: string): nss.object`\
1415
Builds an NSS value from a binary string.\
15-
Non-binary characters are ignored.
16+
An optional `0b`/`0B` prefix is stripped. Throws on non-binary characters.
1617

1718
- `#!ts nss.fromString(str: string): nss.object`\
1819
Builds an NSS value from a decimal string.\
19-
Non-digit characters are ignored.
20+
An optional leading sign (`+`/`-`) is accepted. Throws on non-digit characters.
2021

2122
- `#!ts nss.fromHex(hex: string): nss.object`\
2223
Builds an NSS value from a hexadecimal string.\
23-
Non-hex characters are ignored.
24+
An optional `0x`/`0X` prefix is stripped. Throws on non-hex characters.
2425

2526
- `#!ts nss.fromTable(words: number[]): nss.object`\
2627
Builds an NSS value from its raw 32-bit word array.
2728

2829
- `#!ts nss.fromAny(value: any): nss.object`\
2930
Coerces supported input into an NSS value.\
30-
Accepts existing `nss` objects, numbers, and strings.
31+
Accepts existing `nss` objects, numbers, strings (decimal, `0x…` hex, `0b…` binary), and raw word tables.
32+
33+
- `#!ts nss.getIllionName(index: number): string`\
34+
Returns the short-scale illion name for the given group index (e.g. `1``"million"`, `2``"billion"`).\
35+
Supports arbitrarily large indices using Conway–Wechsler notation.
3136

3237
## Object
3338
Instances are created through the static helpers above or the underlying class constructor.
@@ -50,6 +55,10 @@ Removes and returns the raw word at an index.
5055
- `#!ts nss:resize(size: number)`\
5156
Truncates or zero-pads the internal word array to the requested size.
5257

58+
- `#!ts nss:size(absolute?: boolean): number`\
59+
Returns the number of stored 32-bit words.\
60+
When `absolute` is `true`, returns the total addressable bit count minus one (`words * 32 - 1`).
61+
5362
- `#!ts nss:clone(): nss.object`\
5463
Returns a copy of the current value.
5564

@@ -59,32 +68,78 @@ Removes leading zero words while preserving a single zero word for empty values.
5968
- `#!ts nss:isZero(): boolean`\
6069
Returns whether the value is numerically zero.
6170

71+
- `#!ts nss:isNegative(): boolean`\
72+
Returns whether the value is negative (non-zero and sign is `-1`).
73+
74+
- `#!ts nss:isOdd(): boolean`\
75+
Returns whether the value is odd.
76+
77+
- `#!ts nss:isEven(): boolean`\
78+
Returns whether the value is even.
79+
80+
- `#!ts nss:applySign(sign: number): self`\
81+
Sets the sign to `-1` if `sign == -1`, otherwise `1`, then normalizes.
82+
83+
- `#!ts nss:abs(): nss.object`\
84+
Returns a copy of the value with a positive sign.
85+
86+
- `#!ts nss:negate(): nss.object`\
87+
Returns a copy of the value with the sign flipped.\
88+
Zero always remains positive.
89+
6290
- `#!ts nss:bitlen(): number`\
6391
Returns the effective bit length of the value.
6492

93+
- `#!ts nss:compareAbs(other: any): -1 | 0 | 1`\
94+
Compares the absolute magnitudes of this value and another coerced value.\
95+
Returns `-1`, `0`, or `1`.
96+
6597
- `#!ts nss:compare(other: any): -1 | 0 | 1`\
66-
Compares this value against another coerced value.
98+
Compares this signed value against another coerced value.\
99+
Returns `-1`, `0`, or `1`.
67100

68-
- `#!ts nss:divmodSmall(divisor: number): [nss.object, number]`\
69-
Divides by a small Lua number and returns quotient plus remainder.
101+
- `#!ts nss:isWithin(limit: any): boolean`\
102+
Returns `true` if this value is less than or equal to `limit`.\
103+
Alias: `fitsWithin`.
104+
105+
- `#!ts nss:exceeds(limit: any): boolean`\
106+
Returns `true` if this value is greater than `limit`.\
107+
Alias: `exceedsLimit`.
108+
109+
- `#!ts nss:bound(limit: any, fallback?: any): nss.object | nil, boolean`\
110+
Returns `(clone, true)` if this value is within `limit`.\
111+
Returns `(fallback, false)` if it exceeds `limit` and a fallback is given, otherwise `(nil, false)`.\
112+
Alias: `limit`.
113+
114+
- `#!ts nss:divmodSmall(divisor: number): nss.object, number`\
115+
Divides by a small Lua number and returns the quotient and the integer remainder.
70116

71117
- `#!ts nss:toNumber(): number`\
72118
Converts the value back into a Lua number.\
73119
Large values can exceed normal number precision.
74120

75-
- `#!ts nss:toString(group?: number): string`\
76-
Returns a decimal string representation.\
77-
When `group` is provided, spaces are inserted every `group` characters.
121+
- `#!ts nss:toString(): string`\
122+
Returns a decimal string representation.
78123

79-
- `#!ts nss:toBinary(group?: number): string`\
80-
Returns a binary string representation.\
81-
When `group` is provided, spaces are inserted every `group` characters.
124+
- `#!ts nss:toBinary(): string`\
125+
Returns a binary string representation.
82126

83127
- `#!ts nss:toHex(): string`\
84128
Returns an uppercase hexadecimal string representation.
85129

86130
- `#!ts nss:toTable(): number[]`\
87-
Returns a copy of the internal word array.
131+
Returns a copy of the internal word array.\
132+
Negative values include a `sign = -1` field.
133+
134+
- `#!ts nss:toScientific(decimals?: number): string`\
135+
Returns a scientific-notation string (e.g. `"1.23e6"`).\
136+
`decimals` defaults to `3`. Trailing fractional zeros are stripped.\
137+
Alias: `toExponential`.
138+
139+
- `#!ts nss:toNamed(decimals?: number): string`\
140+
Returns a short-scale named string (e.g. `"1.2 million"`).\
141+
`decimals` defaults to `1`. Values below one thousand are returned as plain decimal.\
142+
Alias: `toShortScale`.
88143

89144
## Bitwise
90145
All operands are coerced with `nss.fromAny(...)` and return new NSS objects.
@@ -121,11 +176,22 @@ Multiplies two values using 32-bit word multiplication.
121176

122177
- `#!ts nss:div(other: any): nss.object`\
123178
Returns the integer quotient of division.\
124-
Division by zero yields `0`.
179+
Throws on divide by zero.
180+
181+
- `#!ts nss:divmod(other: any): nss.object, nss.object`\
182+
Returns the integer quotient and signed remainder as two values.\
183+
Throws on divide by zero.
184+
185+
- `#!ts nss:divmodAbs(other: any): nss.object, nss.object`\
186+
Returns the quotient and remainder of the absolute magnitudes as two values.\
187+
Throws on divide by zero.
188+
189+
- `#!ts nss:mod(other: any): nss.object`\
190+
Returns the signed remainder of division.
125191

126192
- `#!ts nss:pow(other: any): nss.object`\
127-
Raises the value to an exponent.\
128-
The exponent is converted through `toNumber()`, so very large exponents are not practical.
193+
Raises the value to an exponent using binary exponentiation.\
194+
Throws if the exponent is negative.
129195

130196
- `#!ts nss:factorial(limit?: number): nss.object`\
131197
Returns `n!`.\

docs/stylesheets/extra.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,13 @@
141141
background-position: 4rem 0;
142142
}
143143
}
144+
145+
.paused .progress-bar {
146+
animation: progress-paused 2s ease-in-out infinite;
147+
background-color: #ff1744;
148+
}
149+
150+
@keyframes progress-paused {
151+
0%, 100% { background-color: #ff1744; }
152+
50% { background-color: #4a0010; }
153+
}

0 commit comments

Comments
 (0)