import { NumericType } from "../../math/NumericType.js";
import { BinaryDataType } from "./BinaryDataType.js";

/**
 *
 * @param {NumericType} type
 * @param {number} precision
 * @returns {BinaryDataType}
 */
export function computeBinaryDataTypeByPrecision(type, precision) {
    if (type === NumericType.Uint) {
        if (precision <= 8) {
            return BinaryDataType.Uint8;
        } else if (precision <= 16) {
            return BinaryDataType.Uint16;
        } else if (precision <= 32) {
            return BinaryDataType.Uint32;
        }
    } else if (type === NumericType.Int) {
        if (precision <= 8) {
            return BinaryDataType.Int8;
        } else if (precision <= 16) {
            return BinaryDataType.Int16;
        } else if (precision <= 32) {
            return BinaryDataType.Int32;
        }
    } else if (type === NumericType.Float) {
        if (precision <= 32) {
            return BinaryDataType.Float32;
        } else if (precision <= 64) {
            return BinaryDataType.Float64;
        }
    }

    throw new Error(`Unsupported numeric type(=${type}) and precision(=${precision}) combination`);
}
