Negative numbers in sqrt() in C++

Revision en2, by kira_lite, 2024-05-11 07:28:10

I observed a very strange behaviour in one of the recent problems of the sqrt() function, where a negative number was passed on to sqrt() function and it worked properly in one way but not the other. I have 2 submissions- one which gives an AC while the other shows Memory out of bounds, which it should have thrown ideally.

The only difference b/w the 2 submissions is that i am having a long long value to subtract from in the AC submission, but i dont see much difference because of it. If someone can provide a brief of why its happening, it'll be a great lesson !

Thanks in advance

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English kira_lite 2024-05-11 07:28:10 10
en1 English kira_lite 2024-05-11 07:27:16 798 Initial revision (published)