thinkeridea / go-extend

go语言扩展包,收集一些常用的操作函数,辅助更快的完成开发工作,并减少重复代码
https://pkg.go.dev/github.com/thinkeridea/go-extend
MIT License
1.34k stars 160 forks source link

exmath.Round 精度为负数时结果精准度问题 #14 #15

Closed thinkeridea closed 3 years ago

thinkeridea commented 3 years ago

该提交用于修复 #14 精度问题,其原因为 precision < 0 其参与计算的浮点数比较小,导致最终运算结果精度得不到保证

分别处理 precision = 0precision <0precision > 0 的情况,以保证精准度为核心目标。

新实现相较于旧方案性能略有下降:

name            old time/op  new time/op  delta
Round-8         3.45ns ± 1%  4.04ns ±14%  +17.25%  (p=0.000 n=44+46)
RoundDecimal-8  3.47ns ± 1%  3.86ns ± 2%  +11.17%  (p=0.000 n=40+50)
RoundInteger-8  4.38ns ± 1%  5.14ns ± 1%  +17.38%  (p=0.000 n=49+48)
codecov[bot] commented 3 years ago

Codecov Report

Merging #15 (7f71041) into main (70de57e) will increase coverage by 0.04%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #15      +/-   ##
==========================================
+ Coverage   90.72%   90.77%   +0.04%     
==========================================
  Files          25       25              
  Lines         787      791       +4     
==========================================
+ Hits          714      718       +4     
  Misses         51       51              
  Partials       22       22              
Impacted Files Coverage Δ
exmath/round.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 70de57e...7f71041. Read the comment docs.