1
0
Fork 0

initial work on fixed

This commit is contained in:
coaljoe 2020-10-26 12:37:34 +03:00
parent 319558d35f
commit 2abb462fef
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
// Fixed-point decimal numbers
// based on https://github.com/robaho/fixed/blob/master/fixed.go
module fixed
import math
const (
n_places = 7
)
pub struct Fixed {
fp i64
}
pub fn new_i(i i64, n u32) Fixed {
mut ii := i
mut nn := n
if nn > n_places {
ii = ii / i64(math.pow(10, int(nn-n_places)))
nn = n_places
}
ii = ii * i64(math.pow(10, int(n_places-nn)))
return Fixed{fp: ii}
}