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

Issue equating zero big.{Int,Float}'s #56

Open
lmittmann opened this issue Jul 31, 2023 · 2 comments
Open

Issue equating zero big.{Int,Float}'s #56

lmittmann opened this issue Jul 31, 2023 · 2 comments

Comments

@lmittmann
Copy link

When comparing std big.Int's or big.Float's there is an edge case for the value zero where is reports the error 0 != 0. The reason for this is the big.{Int,Float} attribute neg bool which can be both true and false for the value zero.

Example

package main

import (
	"math/big"
	"testing"

	"github.com/matryer/is"
)

func TestBig(t *testing.T) {
	is := is.NewRelaxed(t)
	big0 := new(big.Int).Add(big.NewInt(-1), big.NewInt(1))
	is.Equal(new(big.Int), big0)              // big.Int
	is.Equal(new(big.Float), big.NewFloat(0)) // big.Float
}

This will result in:

        is_test.go:13: 0 != 0 // big.Int
        is_test.go:14: 0 != 0 // big.Float
--- FAIL: TestBig (0.00s)
FAIL

It's not really a bug since the structs are different after all. However, since this are std types it would be nice if they would be compared by their Cmp function.

@lmittmann
Copy link
Author

@matryer would you accept a PR?

@breml
Copy link
Contributor

breml commented Aug 26, 2023

Hi @lmittmann
There was a longer discussion about is.Equal and some short comings it currently has in #53 . Before providing a PR, I suggest to you go through the discussion there.

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

2 participants