initial work on fixed
This commit is contained in:
parent
319558d35f
commit
2abb462fef
|
@ -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}
|
||||
}
|
Loading…
Reference in New Issue