6 Star 19 Fork 29

王布衣 / gotdx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
number.go 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-05-07 06:58 . 调整目录结构
package internal
import (
"math"
)
// Float64IsNaN 判断float64是否NaN
func Float64IsNaN(f float64) bool {
return math.IsNaN(f) || math.IsInf(f, 0)
}
func NumberToFloat64[T uint16 | uint32 | float32](v T) float64 {
return float64(v)
}
// IntToFloat64 整型转float64
func IntToFloat64[T ~uint32 | ~int | ~int64](integer T) float64 {
ivol := int(integer)
logPoint := ivol >> (8 * 3)
//hheax := ivol >> (8*3) // [4]
hleax := (ivol >> (8 * 2)) & 0xff // [2]
lheax := (ivol >> 8) & 0xff // [1]
lleax := ivol & 0xff // [0]
//dbl_1 := 1.0
//dbl_2 := 2.0
//dbl_128 := 128.
dwEcx := logPoint*2 - 0x7f
dwEdx := logPoint*2 - 0x86
dwEsi := logPoint*2 - 0x8e
dwEax := logPoint*2 - 0x96
tmpEax := 0
if dwEcx < 0 {
tmpEax = -dwEcx
} else {
tmpEax = dwEcx
}
dblXmm6 := math.Pow(2.0, float64(tmpEax))
if dwEcx < 0 {
dblXmm6 = 1.0 / dblXmm6
}
dblXmm4 := 0.0
if hleax > 0x80 {
tmpdblXmm3 := 0.0
//tmpdblXmm1 := 0.0
dwtmpeax := dwEdx + 1
tmpdblXmm3 = math.Pow(2.0, float64(dwtmpeax))
dblXmm0 := math.Pow(2.0, float64(dwEdx)) * 128.0
dblXmm0 += float64(hleax&0x7f) * tmpdblXmm3
dblXmm4 = dblXmm0
} else {
dblXmm0 := 0.0
if dwEdx >= 0 {
dblXmm0 = math.Pow(2.0, float64(dwEdx)) * float64(hleax)
} else {
dblXmm0 = (1 / math.Pow(2.0, float64(dwEdx))) * float64(hleax)
}
dblXmm4 = dblXmm0
}
dblXmm3 := math.Pow(2.0, float64(dwEsi)) * float64(lheax)
dblXmm1 := math.Pow(2.0, float64(dwEax)) * float64(lleax)
if hleax&0x80 != 0 {
dblXmm3 *= 2.0
dblXmm1 *= 2.0
}
return dblXmm6 + dblXmm4 + dblXmm3 + dblXmm1
}
Go
1
https://gitee.com/quant1x/gotdx.git
git@gitee.com:quant1x/gotdx.git
quant1x
gotdx
gotdx
v1.22.6

搜索帮助