Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Point Arithmetic #12

Closed
4meta5 opened this issue Jun 15, 2019 · 4 comments
Closed

Fixed Point Arithmetic #12

4meta5 opened this issue Jun 15, 2019 · 4 comments
Labels
new recipe 🍳 Request to add a new recipe

Comments

@4meta5
Copy link
Contributor

4meta5 commented Jun 15, 2019

This is a subtle difficulty when working with computers. Floating point arithmetic is nondeterminisic so the basic approach is to use a wrapper type that represents either 1_000_000 (Permill) or 1_000_000_000 (Perbill) times the given floating point value.

I've learned recently that this can get messy. I think it's worth doing a recipe on this.

@4meta5 4meta5 changed the title Floating Point Arithmetoic Floating Point Arithmetic Jun 15, 2019
@4meta5 4meta5 added the priority ⌛ top of the list! label Jun 15, 2019
@4meta5
Copy link
Contributor Author

4meta5 commented Jun 16, 2019

common pattern

  1. start by defining a closure that converts all relevant inputs to the Perbill or Permill parts form; context of computation matters
  2. next define all relevant inputs in terms of this form using the above closure or any on-paper arithmetic
  3. perform intermediate computation with these large numbers => be careful of overflow
  4. convert using Per{bill, mill}::from_parts(arg.min(billion as u32)

testing

  • test with floating point numbers to ensure precision (using staking/inflation for guidance)

@4meta5 4meta5 added tabled 🏓 maybe later... and removed srml tour 🎉 priority ⌛ top of the list! labels Aug 30, 2019
@4meta5
Copy link
Contributor Author

4meta5 commented Aug 31, 2019

focusing on treasury for the time being, waiting for more progress here: pull 3456, issue 3189

@JoshOrndorff
Copy link
Owner

Maybe the recipe should be called Fixed Point Arithmetic.

@4meta5 4meta5 changed the title Floating Point Arithmetic Fixed Point Arithmetic Sep 3, 2019
@JoshOrndorff JoshOrndorff added new recipe 🍳 Request to add a new recipe and removed tabled 🏓 maybe later... labels Feb 16, 2020
@JoshOrndorff
Copy link
Owner

Closed in #196

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new recipe 🍳 Request to add a new recipe
Projects
None yet
Development

No branches or pull requests

2 participants