Pure package detail
fixedpoint
gno.land/p/g16m0r7rm7fv5hx0ekr7gvx8g4fr7eu08nzhk6gt/fixedpoint
Indexed deployment identity with independently loaded latest RPC source. Functions and Render are realm-only RPC capabilities.
Indexed deployment
Identity
- Package path
- gno.land/p/g16m0r7rm7fv5hx0ekr7gvx8g4fr7eu08nzhk6gt/fixedpoint
- Block
- 79300
- Deployed (UTC)
- Transaction
- d+PppEot/lGqM6KaOISQfO/j6sC1AYZDF/6RUrow6fA=
Latest RPC state
Source
package fixedpoint
const Scale = int64(1000000)
type Fixed struct {
Raw int64
}
func New(whole, frac int64) Fixed {
return Fixed{Raw: whole*Scale + frac}
}
func FromInt(i int64) Fixed {
return Fixed{Raw: i * Scale}
}
func (f Fixed) Add(other Fixed) Fixed {
return Fixed{Raw: f.Raw + other.Raw}
}
func (f Fixed) Sub(other Fixed) Fixed {
return Fixed{Raw: f.Raw - other.Raw}
}
func (f Fixed) Mul(other Fixed) Fixed {
return Fixed{Raw: (f.Raw * other.Raw) / Scale}
}
func (f Fixed) Div(other Fixed) Fixed {
if other.Raw == 0 {
panic("fixedpoint: division by zero")
}
return Fixed{Raw: (f.Raw * Scale) / other.Raw}
}
func (f Fixed) String() string {
whole := f.Raw / Scale
frac := f.Raw % Scale
if frac < 0 {
frac = -frac
}
fracStr := itoa(frac)
for len(fracStr) < 6 {
fracStr = "0" + fracStr
}
return itoa(whole) + "." + fracStr
}
func itoa(n int64) string {
if n == 0 {
return "0"
}
neg := n < 0
if neg {
n = -n
}
var buf [20]byte
i := len(buf)
for n > 0 {
i--
buf[i] = byte('0' + n%10)
n /= 10
}
s := string(buf[i:])
if neg {
s = "-" + s
}
return s
}
The verified vm/qfuncs operation accepts realm paths only.
Pure packages expose source files but do not have Realm Render.