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

♻️ HalfStepInt refactor #307

Open
hacheigriega opened this issue Jul 22, 2024 · 0 comments
Open

♻️ HalfStepInt refactor #307

hacheigriega opened this issue Jul 22, 2024 · 0 comments
Labels
type: refactor ♻️ Code change that neither fixes a bug nor adds a feature

Comments

@hacheigriega
Copy link
Member

hacheigriega commented Jul 22, 2024

♻️ Refactor

HalfStepInt was introduced to deal with possible half-step values (0.5) that might appear when we calculate the median of integers.

The current implementation of HalfStepInt uses a number of type T to represent the integer part of a number. However, this is more prone to an overflow while calculating the median than using uint64. The current implementation is also confusing in that the integer field and the neg field are both used to infer the sign of the number. This issue calls for refactoring the code so that it conforms to the following, more straightforward, type:

type HalfStepInt[T constraints.Integer] struct {
	integer  uint64
	neg      bool // if true, the integer is negative
	halfStep bool // if true, the number contains fractional part (0.5)
}

In addition, detect any possible overflow and handle it properly.

@hacheigriega hacheigriega added the type: refactor ♻️ Code change that neither fixes a bug nor adds a feature label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactor ♻️ Code change that neither fixes a bug nor adds a feature
Projects
None yet
Development

No branches or pull requests

1 participant