ALTree / bigfloat

Additional operations for the standard library big.Float type
MIT License
25 stars 10 forks source link

Panic in Pow for negative base with integer exponent #35

Open vsivsi opened 5 years ago

vsivsi commented 5 years ago

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 commented 5 years ago

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