decimal icon indicating copy to clipboard operation
decimal copied to clipboard

Added Sqrt and SqrtRound functionality

Open ldcicconi opened this issue 6 years ago • 7 comments

Based this on https://github.com/shopspring/decimal/pull/111 , but corrected an algorithmic bug.

Not sure why those other changes are showing up.

ldcicconi avatar Jan 16 '19 23:01 ldcicconi

I need decimal to be sqrt(), it's current missed, please merge the function

huahuayu avatar Dec 01 '20 10:12 huahuayu

The implementation overall looks good. If you can @ldcicconi, please rebase it so I can merge it to master and add unit tests for this implementation. If you don't have time I can do it and write unit tests for this implementation.

mwoss avatar Mar 26 '21 00:03 mwoss

@mwoss on it.

ldcicconi avatar Mar 26 '21 00:03 ldcicconi

@mwoss I added some unit tests and made a few other changes. Let me know what you think.

note: the second test case in the vals map currently fails. I must be missing something for numbers near 0.

ldcicconi avatar Mar 27 '21 20:03 ldcicconi

Hmm, I'm not sure why this algorithm is failing on numbers in the range (0, 1). What method you have used for calculating sqrt? Can you point me to the paper or any article?

mwoss avatar Mar 30 '21 21:03 mwoss

Can we get this PR merged? The code looks good, only issue is a couple digit off, and it's way more than enough for most use cases. #222

decimal_test.go:2913: Square root of 0.002342 should be 0.0483942145302514, not 0.0483942145302509 (error: %!s())

thanks

qiquanlu avatar Oct 11 '21 02:10 qiquanlu