Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Floating Point Numbers in Offchain Workers #7685

Open
apopiak opened this issue Dec 7, 2020 · 4 comments
Open

Floating Point Numbers in Offchain Workers #7685

apopiak opened this issue Dec 7, 2020 · 4 comments
Labels
J0-enhancement An additional feature request.
Milestone

Comments

@apopiak
Copy link
Contributor

apopiak commented Dec 7, 2020

Because we don't rely on determinism in offchain workers we could support floating point numbers in principle.
What are the obstacles for enabling this?

@apopiak apopiak added the J0-enhancement An additional feature request. label Dec 7, 2020
@apopiak apopiak added this to the Ideas milestone Dec 7, 2020
@kianenigma
Copy link
Contributor

I am bit unsure what we would even have to do to support float? I thought that it is always there, we just discourage it.

@xlc
Copy link
Contributor

xlc commented Dec 7, 2020

How do you ensure the float included code will not get called by on-chain logic?

We are using fixed point number and it is doing fine for us.

@jak-pan
Copy link
Contributor

jak-pan commented Dec 8, 2020

This probably spun out of my question.

The reason I asked this initially was that we wanted to get a price from an oracle included in the blockchain which is deserialized as float and method from_fraction() of Fixed numbers is hidden behind std flag. We all understand that we shouldn't use floats in runtime but it seemed like these convenience functions should be available.

@apopiak however pointed other way to do this easily by using lite-json so it might be non-issue.

The question IMO is still interesting though. As long as you pass correct data to the runtime, why should ocw logic be constrained like runtime is?

@gui1117
Copy link
Contributor

gui1117 commented Dec 8, 2020

The question IMO is still interesting though. As long as you pass correct data to the runtime, why should ocw logic be constrained like runtime is?

I think feature gating float usage with flag "std" allowed us not to use float accidentally in the runtime. As far as I know float are supported in the runtime and you can use them.

Maybe we could introduce a new feature "ocw" and always ensure the runtime (without offchain worker) compiles without "ocw" feature and pass test suite. But this doesn't completely prevent us from using "ocw" feature accidentally in the runtime.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request.
Projects
None yet
Development

No branches or pull requests

5 participants