0

Floating-point arithmetic are not allowed in substrate runtime.

f64 has an pub fn ln(self) -> f64 to calculate natural log. How can I do that in substrate without using floating points.

3
  • You can work with different representation of numbers. For example after getting an answer like 2.5 you do 2.5 * 10 and in the front end you can divide back. Commented Jun 13, 2022 at 18:05
  • In what context do you want to use this? What base specifically do you need? Perhaps e also know as natural? What accuracy do you need in the result and why?
    – Nuke
    Commented Jun 13, 2022 at 21:23
  • Was thinking of logarithmic inflation of tokens. 4 to 5 decimal accuracy would be fine. Commented Jun 14, 2022 at 9:57

1 Answer 1

1

There is a great library to handle the float calculation.

For your case, you can use substrate_fixed::transcendental::ln.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.