File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ limitations under the License.
1616
1717package integer
1818
19+ import "math"
20+
1921// IntMax returns the maximum of the params
2022func IntMax (a , b int ) int {
2123 if b > a {
@@ -65,9 +67,7 @@ func Int64Min(a, b int64) int64 {
6567}
6668
6769// RoundToInt32 rounds floats into integer numbers.
70+ // Deprecated: use math.Round() and a cast directly.
6871func RoundToInt32 (a float64 ) int32 {
69- if a < 0 {
70- return int32 (a - 0.5 )
71- }
72- return int32 (a + 0.5 )
72+ return int32 (math .Round (a ))
7373}
Original file line number Diff line number Diff line change @@ -233,6 +233,10 @@ func TestRoundToInt32(t *testing.T) {
233233 num : 0 ,
234234 exp : 0 ,
235235 },
236+ {
237+ num : 0.49999999999999994 ,
238+ exp : 0 ,
239+ },
236240 }
237241
238242 for i , test := range tests {
You can’t perform that action at this time.
0 commit comments