An int64 value is odd when n % 2 != 0. Keep strconv.ParseInt errors separate from the parity result.
In Go, use n % 2 != 0 to check an integer for oddness. A small helper with an int64 parameter gives the input a fixed width across platforms. That is useful when the number arrives from a file, a database, or another service with a signed 64-bit contract.
A fixed-width integer helper
package main
import (
"fmt"
"strconv"
)
func isOdd(n int64) bool {
return n%2 != 0
}
func main() {
n, err := strconv.ParseInt("-105", 10, 64)
if err != nil {
fmt.Println("invalid signed 64-bit integer")
return
}
fmt.Println(isOdd(n)) // true
}
Check parsing errors and input format
ParseInt receives an explicit decimal base and a 64-bit size. Check err before using the returned number. An out-of-range parse can return a boundary value together with an error, so ignoring the error can produce a plausible answer for input that was never accepted. The strconv documentation describes this behavior.
Choosing base ten also makes the input grammar easier to explain: the user is supplying a decimal integer. Do not select automatic base detection unless prefixes such as hexadecimal are part of your interface. The parser does not trim whitespace; apply strings.TrimSpace explicitly if the surrounding application wants to accept it.
Test signed remainder behavior
Negative odd values need a nonzero comparison. Go's integer division truncates toward zero, and its remainder follows that relationship. Thus -105 % 2 is -1. A predicate using == 1 would incorrectly return false. The Go specification gives the quotient and remainder rules.
Try these cases when reviewing the helper:
var samples = []int64{-6, -5, 0, 5, 6}
for _, n := range samples {
fmt.Println(n, isOdd(n))
}
The expected odd values are -5 and 5. Add the smallest and largest int64 values if your input contract permits the complete range. The implementation never negates its input or adds one, which keeps those tests focused on parity rather than on an unnecessary intermediate operation.
Choose the type that matches the data
Go's plain int may be a different width on different target architectures. A helper accepting int is perfectly reasonable for local slice indexes, while a fixed-width helper fits a fixed-width storage format. Choose the parameter type to match the data rather than converting every value to the widest type by habit.
The remainder operator applies to integers in Go. If input starts as a floating-point measurement, converting it to int64 is a separate data decision and can discard its fractional part. Reject inappropriate measurements at the boundary instead of allowing the cast to redefine the question. This calculation needs no dependency, background goroutine, or network call.