1
0
mirror of https://github.com/uptrace/go-clickhouse.git synced 2025-06-06 23:16:18 +02:00
go-clickhouse/ch/bfloat16/bfloat16.go

24 lines
317 B
Go
Raw Normal View History

2022-07-14 10:41:44 +03:00
package bfloat16
import (
"math"
)
type T uint16
func From(f float64) T {
2023-04-27 09:22:40 +03:00
return From32(float32(f))
2022-07-14 10:41:44 +03:00
}
2023-04-27 09:22:40 +03:00
func From32(f float32) T {
2022-07-14 10:41:44 +03:00
return T(math.Float32bits(f) >> 16)
}
func (f T) Float32() float32 {
return math.Float32frombits(uint32(f) << 16)
}
func (f T) Float64() float64 {
return float64(f.Float32())
}