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

Pow(Inf, -1) == 0 not Inf. True for all negative exponents #36

Open
vsivsi opened this issue Apr 12, 2019 · 2 comments
Open

Pow(Inf, -1) == 0 not Inf. True for all negative exponents #36

vsivsi opened this issue Apr 12, 2019 · 2 comments

Comments

@vsivsi
Copy link

vsivsi commented Apr 12, 2019

Hi again, this one is more of an edge case... But for consistency with math.Pow()

Also, for -Inf: Pow(-Inf, -1) == -0, but this also doesn't work because of #35

Thanks again!

package main

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

	"github.com/ALTree/bigfloat"
)

func main() {
	// Exponentiation of Inf^n equals 0 for all negative n
	// e.g. Inf^-2 = 0

	zero := math.Pow(math.Inf(1), -2)
        fmt.Printf("%f\n", zero)     //   0.000000

	bigneg2 := big.NewFloat(-2)
	bigInf := big.NewFloat(0.0).SetInf(false)
	bigzero := bigfloat.Pow(bigInf, bigneg2)   
	fmt.Printf("%f\n", bigzero)  //   +Inf  !=  0.000000
}
@vsivsi
Copy link
Author

vsivsi commented Apr 12, 2019

Repro for second case of -Inf:

package main

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

	"github.com/ALTree/bigfloat"
)

func main() {
	// Exponentiation of -Inf^n equals -0 for all odd negative integer n
	// e.g. -Inf^-1 = -0
	// Exponentiation of -Inf^n equals 0 for all even negative integer n
	// e.g. -Inf^-2 = 0

	zero := math.Pow(math.Inf(-1), -1)
	fmt.Printf("%f\n", zero)     //   0.000000
	fmt.Printf("%t\n", math.Signbit(zero))     //   true == negative zero

	zero = math.Pow(math.Inf(-1), -2)
	fmt.Printf("%f\n", zero)     //   0.000000
	fmt.Printf("%t\n", math.Signbit(zero))     //   false == positive zero

	bigneg1 := big.NewFloat(-1)
	bignegInf := big.NewFloat(0.0).SetInf(true)
	bignegzero := bigfloat.Pow(bignegInf, bigneg1)	//  PANIC!    
	fmt.Printf("%f\n", bignegzero)			//  Should be -0.000000
	fmt.Printf("%t\n", bignegzero.Signbit())	//  Should be true

	bigneg2 := big.NewFloat(-2)
	bigzero := bigfloat.Pow(bignegInf, bigneg2)	//  PANIC!    
	fmt.Printf("%f\n", bigzero)			//  Should be 0.000000
	fmt.Printf("%t\n", bigzero.Signbit())		//  Should be false

}

@vsivsi
Copy link
Author

vsivsi commented Apr 15, 2019

See #37

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