math/big's big.Int has a power function: https://golang.org/pkg/math/big/#Int.Exp
I wrote a power function for big.Float you can find here: https://github.com/l0k1verloren/float256/blob/master/float256.go#L82 It doesn't check for overflows because I don't think big.Float overflows from 64 bit exponents though maybe it could from a big enough base. On Wednesday, 11 July 2012 06:22:15 UTC+3, Ondekoza wrote: > > How do I idiomatically calculate "the power of" with integers? > > z := 3^4 // Nooo, ^ caret is bitwise negation > z := 3**4 // Nooo, invalid indirect > z := math.Pow(3,4) // Correct, but converting 3 and 4 to float, and the > result. > BigInt? I cannot provide an example, because I cannot understand from the > docs how to convert a 3 to a Bigint. > > Is the big package (using ints) better or converting to float first (using > the math-package)? > Would you see 2^x as a special case (using shifting)? > > > -- 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.