Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Update floats.md #85

Open
wants to merge 2 commits into
base: apopiak-floats
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions current/runtime/floats.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ lang: en
title: Floating Point Numbers
---

When developing for the Substrate runtime and doing calculations it is appealing to use floating point numbers for e.g. representing fractions. This document covers why traditional floating point numbers are problematic in a runtime context and what alternatives exist.
When developing for the Substrate runtime and doing calculations it is appealing to use floating point numbers for e.g. representing fractions. In Substrate it is important that each node arrives at the same deterministic result for consensus. This document covers why traditional floating point numbers are problematic in runtime and what alternatives exist.

## Problems with Floating Point Numbers in the Runtime
## Problems with Floating Point Numbers in Runtime
wheresaddie marked this conversation as resolved.
Show resolved Hide resolved

Floating point numbers are not deterministic and thus cannot be used to run a deterministic block production algorithm. The standard way of handling rational (or real) numbers depends on how many decimal places are needed and then choosing one of the in-built primitive types in Substrate providing fixed point arithmetic. Fixed point computation is safe for Substrate since it represents all rationals as a fraction thus resolving to a deterministic result. The two types which are used to handle large fixed point arithmetic are `Permill` and `Perbill`, you can refer to [safe math](https://substrate.dev/recipes/3-entrees/safemath.html) for further information and implementation.

## Alternatives

Expand Down