import { assert } from "../assert.js";

/**
 * @see https://www.w3.org/TR/WGSL/#roundup
 * @param {number} x what to round
 * @param {number} divisor divisor positive integer
 * @return {number}
 *
 * @example
 *  round_up(10, 2) === 10
 *  round_up(11, 2) === 12
 *  round_up(1, 10) === 10
 *  round_up(9, 10) === 10
 *  round_up(11, 10) === 20
 */
export function round_up(x, divisor) {
    assert.isNonNegativeInteger(divisor, 'k');
    assert.isNumber(x, 'n');
    assert.notNaN(x, 'n');

    return Math.ceil(x / divisor) * divisor
}