Middle
What is the result of dividing an integer value by zero and dividing a floating-point number by zero?
sobes.tech AI
Answer from AI
In Golang:
Integer division by zero causes a runtime panic (panic: integer divide by zero).
Floating-point division by zero results in special values: +Inf (positive infinity) for positive numbers and -Inf (negative infinity) for negative numbers. Dividing 0.0 by 0.0 yields NaN (Not a Number).
Example:
package main
import "fmt"
func main() {
// Integer division by 0 causes a panic
// var i int = 10
// fmt.Println(i / 0) // Uncomment to demonstrate panic
// Floating-point division by 0
var f float64 = 10.0
fmt.Println(f / 0.0) // +Inf
var f2 float64 = -10.0
fmt.Println(f2 / 0.0) // -Inf
var f3 float64 = 0.0
fmt.Println(f3 / 0.0) // NaN
}