github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/test/contracts/uniswap/v2/UQ112x112.sol (about) 1 pragma solidity =0.5.16; 2 3 // a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format)) 4 5 // range: [0, 2**112 - 1] 6 // resolution: 1 / 2**112 7 8 library UQ112x112 { 9 uint224 constant Q112 = 2**112; 10 11 // encode a uint112 as a UQ112x112 12 function encode(uint112 y) internal pure returns (uint224 z) { 13 z = uint224(y) * Q112; // never overflows 14 } 15 16 // divide a UQ112x112 by a uint112, returning a UQ112x112 17 function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) { 18 z = x / uint224(y); 19 } 20 }