| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | /** Simple math utilities for branded numbers */ |
| 9 | |
| 10 | /** `+` but preserves the return type. */ |
| 11 | export function next<T extends number>(rev: T, offset = 1): T { |
| 12 | return (rev + offset) as T; |
| 13 | } |
| 14 | |
| 15 | /** `-` but preserves the return type. */ |
| 16 | export function prev<T extends number>(rev: T, offset = 1): T { |
| 17 | return (rev - offset) as T; |
| 18 | } |
| 19 | |
| 20 | /** `Math.max` but preserves the return type. */ |
| 21 | export function max<T extends number>(...values: Array<T | number>): T { |
| 22 | return Math.max(...values) as T; |
| 23 | } |
| 24 | |