Skip to content

Latest commit

 

History

History
114 lines (54 loc) · 2.73 KB

u8.md

File metadata and controls

114 lines (54 loc) · 2.73 KB

Module 0x1::u8

Function max

Return the larger of x and y

public fun max(x: u8, y: u8): u8

Function min

Return the smaller of x and y

public fun min(x: u8, y: u8): u8

Function diff

Return the absolute value of x - y

public fun diff(x: u8, y: u8): u8

Function divide_and_round_up

Calculate x / y, but round up the result.

public fun divide_and_round_up(x: u8, y: u8): u8

Function multiple_and_divide

Returns x * y / z with as little loss of precision as possible and avoid overflow

public fun multiple_and_divide(x: u8, y: u8, z: u8): u8

Function pow

Return the value of a base raised to a power

public fun pow(base: u8, exponent: u8): u8

Function sqrt

Get a nearest lower integer Square Root for x. Given that this function can only operate with integers, it is impossible to get perfect (or precise) integer square root for some numbers.

Example:

u8::sqrt(9) => 3
u8::sqrt(8) => 2 // the nearest lower square root is 4;
public fun sqrt(x: u8): u8