Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic in Pow for negative base with integer exponent #35

Open
vsivsi opened this issue Apr 12, 2019 · 1 comment
Open

Panic in Pow for negative base with integer exponent #35

vsivsi opened this issue Apr 12, 2019 · 1 comment

Comments

@vsivsi
Copy link

vsivsi commented Apr 12, 2019

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant