Questions tagged [fixed-point]
The fixed-point tag has no usage guidance.
12
questions
1
vote
1
answer
38
views
Solidity 128.128 unsigned fixed point division
I am currently trying to figure out a concrete way to perform fixed point division on two 128.128 uint256 numbers. This seems like a fairly straightforward thing, but haven't been able to code a ...
0
votes
0
answers
38
views
Handling fractions and fixed point number division
A contract im trying to implement distributes rewards to depositors, lets say
totalDepositsWei = 2e18
totalRewardWei = 1e18
In my contract i'm effectively keeping track of reward per deposit which ...
0
votes
0
answers
25
views
How to deal with funds lost to rounding errors in DeFi protocols?
What are the different methods that DeFi protocols use to handle rounding errors? For example say I have an ICO contract that returns 1/1e10 of the ICO token per ETH, so if you deposit 1 ETH(1e18 wei) ...
2
votes
1
answer
118
views
How to floor or ceil a fixed point number?
Say I have a signed 64.64 fixed point number 18444899399302180000 or 0.9999 in floating point notation. How can I define a floor and ceil function that floors or ceils an int128 signed 64.64 fixed ...
5
votes
1
answer
768
views
What does `decode112with18` do?
In a Solidity fixed point library, the function decode112with18 converts a uq112x112 to a uint value and I'm wondering what exactly is happening in the function. Thanks.
// decode a uq112x112 into ...
3
votes
0
answers
506
views
Converting Uniswap sqrtPriceX96 into wei
I'm trying to figure out how to convert a uniswap ratio into wei (and eventually ether).
The uniswap docs commonly mention sqrtPriceX96:
A Fixed point Q64.96 number representing the sqrt of the ratio ...
0
votes
1
answer
73
views
How in Solidity can you get initial value from the sum of ratios to it?
In Solidity division of uint256 rounds down the value. Let's say I want to issue some token amount based on duration like this:
uint256 MAX_TIME = 365 days;
uint256 Duration1 = 223 days;
uint256 ...
0
votes
0
answers
215
views
DeclarationError: Identifier already declared even with inline function call
I got error in my smart contract,
Pool.sol:10:1: DeclarationError: Identifier already declared.
import './ERC20.sol';
^------------------^
Token.sol:10:1: The previous declaration is here:
contract ...
0
votes
1
answer
83
views
Rounding fixed point integers
If I'm using fixed-point arithmetic to represent rates, for example, 2% in ray (27 decimal precision) would be 102000000000000000000000000000.
If I had a rate like 101333333333333333333333333333 (1.33%...
0
votes
0
answers
76
views
Can't store the value of a math operation. It's always 0
contract MyContract {
uint public priceUSD = 1.70 * 10**8; // USD
uint public priceEth;
.........
function setPrice(uint newPriceUSD) external ownerOnly() returns(uint, uint) {
uint ...
1
vote
1
answer
220
views
Why don't decimals work in solidity?
I've read this question and answer thread about representing decimal values in solidity, and I understand that math is entirely done using fixed-point.
However, I'm curious as to why this is the case. ...
20
votes
4
answers
16k
views
Can't do any integer division
I'm building a new smart contract but really can't figure out how to perform integer division. I know that fixed point numbers haven't been implemented yet but it should be possible to perform 100/3 = ...