succd: implement threshold outputs, rework processing
This commit is contained in:
parent
781bbaaeb4
commit
6d97eb62a8
5 changed files with 323 additions and 167 deletions
33
succbone/succd/scientific.go
Normal file
33
succbone/succd/scientific.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ScientificNotationValue float64
|
||||
|
||||
func (s *ScientificNotationValue) UnmarshalText(text []byte) error {
|
||||
f, err := strconv.ParseFloat(string(text), 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*s = ScientificNotationValue(f)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ScientificNotationValue) MarshalText() ([]byte, error) {
|
||||
v := float64(*s)
|
||||
exp := 0
|
||||
for v < 1 {
|
||||
v *= 10
|
||||
exp -= 1
|
||||
}
|
||||
for v >= 10 {
|
||||
v /= 10
|
||||
exp += 1
|
||||
}
|
||||
res := fmt.Sprintf("%.3f", v)
|
||||
res += fmt.Sprintf("e%d", exp)
|
||||
return []byte(res), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue