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

Create sqrt.go #111

Closed
wants to merge 1 commit into from
Closed

Create sqrt.go #111

wants to merge 1 commit into from

Conversation

kempeng
Copy link

@kempeng kempeng commented Aug 19, 2018

Implementation of Square Root for decimals

Implementation of Square Root for decimals
Copy link

@ldcicconi ldcicconi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to consider the case that 0 < d < 1 .

Something like

	if d.GreaterThanOrEqual(decimal.One) {
		lo = decimal.Zero
		hi = d
	} else if d.Equal(decimal.One) {
		return one
	} else if d.LessThan(decimal.Zero) {
		return decimal.NewFromFloat(-1), false // this is an error here, cant take sqrt of neg w/o imaginaries
	} else if d.Equal(decimal.Zero) {
		return decimal.Zero
	} else {
		// d is between 0 and 1. Therefore, 0 < d < Sqrt(d) < 1.
		lo = d
		hi = one
	}

@mwoss
Copy link
Member

mwoss commented Mar 30, 2021

Improved implementation, with edge case handling in #130. I'm closing this PR.

@mwoss mwoss closed this Mar 30, 2021
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

Successfully merging this pull request may close these issues.

None yet

3 participants