succd: implement threshold outputs, rework processing

This commit is contained in:
Serge Bazanski 2024-09-27 02:11:04 +02:00
parent 781bbaaeb4
commit 6d97eb62a8
5 changed files with 323 additions and 167 deletions

View 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
}