Skip to main content

Questions tagged [floating-point-math]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer

IEEE 754 Floating Point Numbers wasm impelementation

We are looking to enable reproducible floating point operations on chain by implementing the IEEE 754 standard as an on-chain wasm function. As discussed in this stackoverflow post, substrate does not ...
Mathis Wellmann's user avatar
3 votes
1 answer

How to use FixedU128?

I'm fetching floating value in offchain worker though lite-json. Json data: { "price": 0.5 } Here is the implementation to fetch the price: let price_str = match obj.clone() { ...
Deepak Chaudhary's user avatar
2 votes
0 answers

How to fetch floating no in offchain worker?

I want to fetch the floating value in offchain worker. I'm using lite_json for http request. Api data: { "price": 0.5 } To fetch and store this price from api. I'm defining a struct: pub ...
Deepak Chaudhary's user avatar
4 votes
3 answers

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 ...
Sokrates's user avatar
  • 421
4 votes
1 answer

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 ...
Alex Bean's user avatar
  • 5,722
0 votes
0 answers

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.
Amiya Behera's user avatar
1 vote
1 answer

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 ...
Chralt's user avatar
  • 543
4 votes
1 answer

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)] ...
yonatan hornstein's user avatar
4 votes
2 answers

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 ...
Shawn Tabrizi's user avatar
  • 16k