fullyallocated
fullyallocated

Reputation: 115

Exponentiation of fixed-point numbers (i.e., a^b) in Solidity

I already know how to calculate x^n, where x is a floating point number and n is an integer. However, I want to implement a price curve, using the formula:

y = 0.5 * (x^1.5)

To do this, I need to be able to do exponentiation where the power is a floating-point (or fixed-point) value. How can I do this in Solidity?

Upvotes: 2

Views: 1874

Answers (1)

Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83438

Solidity does not offer built-in math functions, therefore you must use a library.

Paul Berg's PRB-math library provides fixed-point mathematics operations for Solidity.

Upvotes: 2

Related Questions