When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
!cppref sqrt
float sqrt(float arg);
// ... and 5 more
so what part are you struggling with?
checking if it's a square numbers is quite simple when you have the square root
and what is your code so far
can't help you without seeing any code
also debugging is important, it's very easy and a great help for finding issues
sqrt() has some very heavy requirements on correctness (compared to other math functions). It is also usually hardware implemented (sqrtss/sqrtsd). With NaN/inf checks it takes usually less than 16 cycles on modern architectures to get the results. (Sqrt itself having usually ~12 cycles latency).
So checking against square root is the easiest and fastest way
I played around it a bit some time ago, if you expect your numbers not to be square most of the time here is an interesting trick:
https://github.com/Kaznov/imath/blob/master/imath.h#L1287
(just me posting stuff for other people that might be interested)
we should make a solution for arbitrary sizes of integers
I want all of the experts in here now
square-number-checking has turned out to be an avengers-level problem
Hi.
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.