Why doesn't division by zero (or overflow, or underflow) stop the program or trigger an error? http://grouper.ieee.org/groups/754/faq.html
On Mon, May 8, 2017 at 6:57 PM Van Hu <bom.d....@gmail.com> wrote: > Usually I would expect a panic just as Go does with integer, but I just > found this from the Golang spec. It's new information to me that > float-point 0 as divisor isn't specified by standard. > Floating-point operators > > For floating-point and complex numbers, +x is the same as x, while -x is > the negation of x. The result of a floating-point or complex division by > zero is not specified beyond the IEEE-754 standard; whether a run-time > panic <https://golang.org/ref/spec#Run_time_panics> occurs is > implementation-specific. > > A const 0.0 divisor is illegal though: > > The divisor of a constant division or remainder operation must not be zero: > > 3.14 / 0.0 // illegal: division by zero > > > > On Tuesday, May 9, 2017 at 9:48:53 AM UTC+8, Michael Jones wrote: > >> This is the definition of that division. >> >> What result would you prefer? >> > On Mon, May 8, 2017 at 6:45 PM Van Hu <bom....@gmail.com> wrote: >> > Hi, my colleague found this strange behavior in Go today, seems like a bug? >>> >>> package main >>> >>> import ( >>> "fmt" >>> ) >>> >>> func main() { >>> var a float64 = 0.0 >>> fmt.Println(1.0 / a) // prints +Inf >>> } >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "golang-nuts" group. >>> >> To unsubscribe from this group and stop receiving emails from it, send an >>> email to golang-nuts...@googlegroups.com. >> >> >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- >> Michael T. Jones >> michae...@gmail.com >> > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Michael T. Jones michael.jo...@gmail.com -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.