Skip to content

Panic in Pow for negative base with integer exponent #35

Open
@vsivsi

Description

@vsivsi

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions