MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / convertUnit

Function convertUnit

src/compute-engine/numerics/unit-data.ts:379–398  ·  view source on GitHub ↗
(
  value: number,
  fromUnit: string,
  toUnit: string
)

Source from the content-addressed store, hash-verified

377 'Gy',
378 'kat',
379 ].map((unit) => [UNIT_TABLE[unit].dimension.join(','), unit])
380);
381
382/**
383 * Search for a named derived SI unit that matches the given dimension vector
384 * and has scale=1.
385 *
386 * Returns the unit symbol (e.g., 'N', 'J', 'W') or `null` if no match.
387 */
388export function findNamedUnit(dim: DimensionVector): string | null {
389 return NAMED_UNIT_BY_DIMENSION.get(dim.join(',')) ?? null;
390}
391
392/**
393 * Convert a numeric `value` from `fromUnit` to `toUnit`.
394 *
395 * Returns the converted value, or `null` when the units are unknown or
396 * dimensionally incompatible.
397 *
398 * Handles both linear conversions (most units) and affine conversions
399 * (degC, degF) via the optional `offset` field.
400 */
401export function convertUnit(

Callers 3

units.tsFile · 0.90
quantityAddFunction · 0.90
convertCompoundUnitFunction · 0.85

Calls 2

resolveUnitFunction · 0.85
dimensionsEqualFunction · 0.85

Tested by

no test coverage detected