Questions tagged [math]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
26 views

Division and floor rounding with 18 decimals

I am recreating a UNISWAP-like AMM and have encountered problems anytime I want to divide the balances of tokens in my pool. For example: I want to require() that tokens are deposited in the correct ...
1
vote
0answers
14 views

Calculate exponential growth using decimals

Is there any way to calculate the following in Solidity? 468750 * 2.718281828459045 ** (x * 0.003662040962) - 468750 Typically I would convert the decimals using decimal * 10 ** 18 but with the ...
0
votes
0answers
17 views

How to get the square root of a big number as returned by web3.utils.toBN()?

I'm working with big numbers as returned by web3.utils.toBN(). According to the web3 documentation, this function returns a BN.js instance. However, there doesn't seem to be a square root function on ...
0
votes
0answers
21 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 ...
0
votes
0answers
16 views

Calculating price: “Operator / not compatible”

function getLatestPrice() public view returns (int, uint8) { ( uint80 roundID, int price, uint startedAt, uint timeStamp, uint80 answeredInRound ) = priceFeed....
0
votes
1answer
33 views

How can you cheaply choose from a dynamic array randomly, with an oracle generated seed number, in Solidity?

In JS you could use this and call it a day. let randomArrayEntry = myArray[Math.floor(Math.random() * myArray.length)]; However, in Solidity everything is deterministic unless you call an outside ...
0
votes
1answer
29 views

Why DS-Math add WAD/2 or RAY/2 in WAD,RAY multiply function

//rounds to zero if x*y < WAD / 2 function wmul(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, y), WAD / 2) / WAD; } //rounds to zero if x*y < WAD / 2 function rmul(uint x, ...
0
votes
0answers
21 views

calculate exchange rate of WBTC TO WETH in big numbers

i want to calculate how much WETH i will get for a given WBTC amount: const amountsEth = kyber .methods .getExpectedRate( addresses.tokens.wbtc, '...
1
vote
1answer
39 views

How can I use decimal in solidity

how can i calculate: 1083.83 / 8.25 = 131.37. As I see its not possible in simple way. I have tried a lot of math function but not works. Is there any solution for this?
4
votes
0answers
28 views

How can i do 2^0.3 (exponent below 1) using integers?

simple problem, but i can't seem to wrap my head around it in solidity. how can i do 2^0.3 (exponent smaller then 1) in solidity using integers. thanks in advance K.
1
vote
1answer
40 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. ...