Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

fixedpoint source pure

Package fixedpoint provides deterministic decimal arithmetic with a fixed number of decimal places, backed by int64. ...

Overview

Package fixedpoint provides deterministic decimal arithmetic with a fixed number of decimal places, backed by int64. gno.land has no float type reachable from consensus-critical code (and even if it did, floats aren't deterministic across platforms), so any realm doing price/ratio/percentage math needs something like this instead of drifting into ad-hoc basis-points arithmetic scattered everywhere.

A Fixed value stores its number scaled by 10^Decimals in Raw. All arithmetic is overflow-checked via math/overflow and panics rather than silently wrapping -- a wrapped overflow in financial math is a far worse failure mode than a loud panic.

Constants 2

Functions 2

Types 1

type Fixed

struct
1type Fixed struct {
2	Raw int64
3}
source

Methods on Fixed

func Add

method on Fixed
1func (f Fixed) Add(other Fixed) Fixed
source

func Cmp

method on Fixed
1func (f Fixed) Cmp(other Fixed) int
source

func Div

method on Fixed
1func (f Fixed) Div(other Fixed) Fixed
source

func IsZero

method on Fixed
1func (f Fixed) IsZero() bool
source

func Mul

method on Fixed
1func (f Fixed) Mul(other Fixed) Fixed
source

func String

method on Fixed
1func (f Fixed) String() string
source

func Sub

method on Fixed
1func (f Fixed) Sub(other Fixed) Fixed
source

Imports 2

Source Files 2