Skip to main content

Math512Bits

Table of contents

Constructors

Methods

Constructors

constructor

new Math512Bits(): Math512Bits

Returns

Math512Bits

Methods

mulDivRoundDown

mulDivRoundDown(x, y, denominator): u256

Calculates floor(x*y÷denominator) with full precision The result will be rounded down

Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv

Requirements:

  • The denominator cannot be zero
  • The result must fit within u256

Caveats:

  • This function does not work with fixed-point numbers

Parameters

NameTypeDescription
xu256The multiplicand as an u256
yu256The multiplier as an u256
denominatoru256The divisor as an u256

Returns

u256

The result as an u256

Defined in

assembly/libraries/Math512Bits.ts:29


mulShiftRoundDown

mulShiftRoundDown(x, y, offset): u256

Calculates x * y >> offset with full precision The result will be rounded down

Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv

Requirements:

  • The offset needs to be strictly lower than 256
  • The result must fit within u256

Caveats:

  • This function does not work with fixed-point numbers

Parameters

NameTypeDescription
xu256The multiplicand as an u256
yu256The multiplier as an u256
offseti32The offset, can't be greater than 255

Returns

u256

The result as an u256

Defined in

assembly/libraries/Math512Bits.ts:86


mulShiftRoundUp

mulShiftRoundUp(x, y, offset): u256

Calculates x * y >> offset with full precision The result will be rounded up

Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv

Requirements:

  • The offset needs to be strictly lower than 128
  • The result must fit within u256

Caveats:

  • This function does not work with fixed-point numbers

Parameters

NameTypeDescription
xu256The multiplicand as an u256
yu256The multiplier as an u256
offseti32The offset, can't be greater than 128

Returns

u256

The result as an u256

Defined in

assembly/libraries/Math512Bits.ts:150


shiftDivRoundDown

shiftDivRoundDown(x, offset, denominator): u256

Calculates x << offset / y with full precision The result will be rounded down

Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv

Requirements:

  • The offset needs to be strictly lower than 256
  • The result must fit within u256

Caveats:

  • This function does not work with fixed-point numbers

Parameters

NameTypeDescription
xu256The multiplicand as an u256
offseti32The number of bit to shift x
denominatoru256The divisor as an u256

Returns

u256

The result as an u256

Defined in

assembly/libraries/Math512Bits.ts:53


shiftDivRoundUp

shiftDivRoundUp(x, offset, denominator): u256

Calculates x << offset / y with full precision The result will be rounded up

Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv

Requirements:

  • The offset needs to be strictly lower than 128
  • The result must fit within u256

Caveats:

  • This function does not work with fixed-point numbers

Parameters

NameTypeDescription
xu256The multiplicand as an u256
offseti32The number of bit to shift x
denominatoru256The divisor as an u256

Returns

u256

The result as an u256

Defined in

assembly/libraries/Math512Bits.ts:124