Questions tagged [floating-point-math]
The floating-point-math tag has no usage guidance.
6
questions
4
votes
3
answers
336
views
How to calculate square root of a number in ink! smart contract?
In the classic flipper ink! sc example I tried within a function
let dist2: f32 = f32::sqrt(4.0);
and got the error
" function or associated item not found in f32 "
Bearing in mind this ...
4
votes
1
answer
182
views
Balance division in Substrate runtime
I am a bit confused with how to do operations with the Balances in the Substrate runtime. More concrete the division.
The example I want to implement is similar to the Lottery pallet but with shared ...
0
votes
0
answers
62
views
How can I calculate natural log of a number?
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.
1
vote
1
answer
200
views
How to get a percent portion of a balance?
I would like to divide a Balance into two parts. One is 10% of value and another part is 90% of the value. BalanceOf<T> is the Balance of a pallet.
type Balance: AtLeast32BitUnsigned
...
4
votes
1
answer
133
views
Rust ink. Division wont return a number with float point
I'm trying to calculate a value of token by using division operator,
it will return a number higher then 1, but never returns
here is the code of the price calculation:
#[ink(message)]
...
4
votes
2
answers
343
views
Can you use floating point numbers or math in the Runtime?
I would like to do some basic operations in the runtime like:
let new_balance = .5 * old_balance;
Or save a percentage value in the runtime storage.
Or represent the balance of a user like: 3.141592 ...