Make maxExponentPower BigNumber and replace 10 with expBase
@@ -110,8 +110,8 @@ function numberToBits(integer: number, bits: number): number[] {
}
export function integerToFloat(integer: BigNumber, expBits: number, mantissaBits: number, expBase: number): Uint8Array {
- const maxExponentPower = Math.pow(2, expBits) - 1;
- const maxExponent = BigNumber.from(10).pow(maxExponentPower);
+ const maxExponentPower = BigNumber.from(2).pow(expBits).sub(1);
+ const maxExponent = BigNumber.from(expBase).pow(maxExponentPower);
const maxMantissa = BigNumber.from(2).pow(mantissaBits).sub(1);
if (integer.gt(maxMantissa.mul(maxExponent))) {
@@ -158,8 +158,8 @@ export function integerToFloatUp(
mantissaBits: number,
expBase: number
): Uint8Array {
- const maxExponentPower = Math.pow(2, expBits) - 1;
- const maxExponent = BigNumber.from(10).pow(maxExponentPower);
+ const maxExponentPower = BigNumber.from(2).pow(expBits).sub(1);
+ const maxExponent = BigNumber.from(expBase).pow(maxExponentPower);
const maxMantissa = BigNumber.from(2).pow(mantissaBits).sub(1);
if (integer.gt(maxMantissa.mul(maxExponent))) {
