No-Op Rounding Of Converted Integer

ID

go.no_op_math_on_int_to_float

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Code Smell

Language

Go

Tags

CWE:1164, code-style, readability

Description

Reports a rounding call from the math package (math.Ceil, math.Floor, math.Round, math.Trunc) applied to a value that was just converted from an integer — math.Ceil(float64(i)).

Rationale

An integer is already a whole number, so rounding it to the nearest integer returns the same value. The rounding call is dead work and usually a leftover from a refactor. The check resolves the call by its qualified name and fires only when the single argument is a float64/float32 conversion of an integer-typed expression.

import "math"

func fn(i int, f float64) {
    _ = math.Ceil(float64(i)) // FLAW — i is already whole
    _ = math.Ceil(f)          // OK — f is a real float
}

Remediation

Drop the rounding call and use the converted value directly, or round the actual floating-point value if that was the intent.