numbers.ts ×13

Frontier kind: Code frontier

unlabeled · c_1136f7f16b56

942 tests · 3426 LOC · 19 files · introduces 0 tests · 48 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
13 ranges48 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
493 ranges3426 lines · 19 files · Browse complete extent
All tests (intent)
942 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 48 introduced LOC across 13 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/base/common/numbers.ts 48 introduced LOC · 13 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- numbers.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { assert } from './assert.js';
7 >
8 > export function clamp(value: number, min: number, max: number): number {
9 return Math.min(Math.max(value, min), max);
10 }
11 > numbers.ts
12 > /**
13 > * Formats a token count for compact display (e.g. `128K`, `1M`, `1.5M`).
14 > */
15 > export function formatTokenCount(count: number): string {
16 if (count >= 1_000_000) {
17 const value = count / 1_000_000;
25 return count.toString();
26 }
27 > numbers.ts
28 > export function rot(index: number, modulo: number): number {
29 return (modulo + (index % modulo)) % modulo;
30 }
31 > numbers.ts
32 > export class Counter {
33 private _next = 0;
34 > numbers.ts
35 > getNext(): number {
36 return this._next++;
37 }
38 > } numbers.ts
39 >
40 > export class MovingAverage {
41
42 private _n = 1;
43 private _val = 0;
44 > numbers.ts
45 > update(value: number): number {
46 this._val = this._val + (value - this._val) / this._n;
47 this._n += 1;
48 return this._val;
49 }
50 > numbers.ts
51 > get value(): number {
52 return this._val;
53 }
54 > } numbers.ts
55 >
56 > export class SlidingWindowAverage {
57 >
58 > private _n: number = 0;
59 > private _val = 0;
60 >
61 > private readonly _values: number[] = [];
62 > private _index: number = 0;
63 > private _sum = 0;
64 >
65 > constructor(size: number) {
66 this._values = new Array(size);
67 this._values.fill(0, 0, size);
68 }
69 > numbers.ts
70 > update(value: number): number {
71 const oldValue = this._values[this._index];
72 this._values[this._index] = value;
83 return this._val;
84 }
85 > numbers.ts
86 > get value(): number {
87 return this._val;
88 }
89 > } numbers.ts
90 >
91 > /** Returns whether the point is within the triangle formed by the following 6 x/y point pairs */
92 > export function isPointWithinTriangle(
93 x: number, y: number,
94 ax: number, ay: number,
115 return u >= 0 && v >= 0 && u + v < 1;
116 }
117 > numbers.ts
118 > export function randomChance(p: number): boolean {
119 assert(p >= 0 && p <= 1, 'p must be between 0 and 1');
120 return Math.random() < p;