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

Division algorithm not specified or consistent #1188

Open
austinabell opened this issue Sep 30, 2020 · 0 comments
Open

Division algorithm not specified or consistent #1188

austinabell opened this issue Sep 30, 2020 · 0 comments

Comments

@austinabell
Copy link

It is not mentioned anywhere in the spec, but there is no distinction between which division algorithm is used. By default, golang uses truncating division for integers and the big.Int library that is used does Euclidean division.

An example of where the difference can be seen:

func TestDivRounding(t *testing.T) {
	dd = big.NewInt(200)
	dv = big.NewInt(3)
	r = big.Div(dd, dv)
	assert.Equal(t, r.Int64(), int64(66))

	ddi = int64(200)
	dvi = int64(3)
	ri = ddi / dvi
	assert.Equal(t, ri, int64(66))

	dd = big.NewInt(-100)
	dv = big.NewInt(3)
	r = big.Div(dd, dv)
	assert.Equal(t, r.Int64(), int64(-34))

	ddi := int64(-100)
	dvi := int64(3)
	ri := ddi / dvi
	assert.Equal(t, ri, int64(-33))
}

There was a discrepancy when calculating the AlphaBetaFilter estimate in the reward actor with this test vector during the first update network KPI call which updates the filter estimate. The division happened at this line if it helps.

This behaviour, especially since both division algorithms are used in the protocol, should at least be written in the spec

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