On Sat, Aug 20, 2016 at 1:24 PM, Bakul Shah <ba...@bitblocks.com> wrote: > > In Go there are two issues: > The compiler refuses to divide by the constant 0.0 — This operation has a > well defined meaning but the compiler thinks it knows best (this behavior is > documented in the spec, which is good, but I don’t see the rationale for > this behavior).
I agree that it was probably a mistake to make division by constant zero a compiler error. But it's not a problem in practice: the only reason to divide by constant zero is to get a floating point infinity, and it's clearer and equally efficient to use math.Inf. > So one has to use a variable to test this … where we run > into the second problem: -0.0 is treated the same as +0.0: > > x := -0.0 > fmt.Println(1.0/x) > > This prints +Inf, when it should be printing -Inf. One has to explicitly > negate x as in > > fmt.Println(1.0/-x) This is by design. Constants in Go are untyped. Floating point constants in particular are not IEEE-754 values. There are no untyped negative zeroes or infinities in Go. There is no floating point constant overflow--or, rather, any such overflow is a compilation error. See https://golang.org/ref/spec#Constants . Ian -- 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.