Incorrect arithmetic answers

95 views
Skip to first unread message

Saksham Saxena

unread,
Jun 1, 2020, 2:56:55 PM6/1/20
to golang-nuts
Hello,

I was trying to implement Substring Search using a rolling hash function (fairly simple implementation): https://play.golang.org/p/_fjgxPC06So

This works correctly and as expected. However, if you change the const `baseNumber` to 128, the program is unable to do the intermediate arithmetic incorrectly (see the difference after running it). 

How could this be ? I've stared at it long enough and it doesn't seem like it's overflowing (or is it really ? I thought float64 had great range ?)

Any ideas/comments are appreciated. 

Thanks!
Saksham

crate...@gmail.com

unread,
Jun 1, 2020, 3:21:03 PM6/1/20
to golang-nuts

Michael Jones

unread,
Jun 1, 2020, 3:47:33 PM6/1/20
to crate...@gmail.com, golang-nuts
fixed, in light of the prior crucial comment...

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d071b2be-9fc1-45e4-9da8-baecb9968ea7%40googlegroups.com.


--
Michael T. Jones
michae...@gmail.com
Reply all
Reply to author
Forward
0 new messages