bigfloat icon indicating copy to clipboard operation
bigfloat copied to clipboard

Panic in Pow for negative base with integer exponent

Open vsivsi opened this issue 5 years ago • 1 comments

Hi, Thanks for this great little package!

The bigfloat.Pow() function seems a little too restrictive relative to the math.Pow() standard library equivalent for negative bases with integer exponents (which are well-defined).

Thanks!

package main

import (
	"fmt"
        "math"
	"math/big"

	"github.com/ALTree/bigfloat"
)

func main() {
	// Exponentiation of all negative bases is well defined for all 
	// integer valued exponents.   e.g. -2^-2 = 0.25

	quarter := math.Pow(-2, -2)
        fmt.Printf("%f\n", quarter)     // 0.250000

	bigneg2 := big.NewFloat(-2)
	bigquarter := bigfloat.Pow(bigneg2, bigneg2)  // PANIC!  Pow: negative base
	fmt.Printf("%f\n", bigquarter)
}

vsivsi avatar Apr 12 '19 20:04 vsivsi

See https://github.com/ALTree/bigfloat/pull/37

vsivsi avatar Apr 15 '19 23:04 vsivsi