Quote Originally Posted by g4j31a5 View Post
Is this right?
It depends on what you are really trying to achieve. Are you trying to test that it works correctly for some specified set of values relevant to some program, or are you trying to check if it works for all possible arguments?

If your objective is the first, then your approach will work.

If you are trying to demonstrate through testing that it always works as described, then your approach is insufficient. Firstly, you will need to somehow test for every feasible value of x and every feasible value of exponent. Second, you will need to find a way of obtaining the right answer for each set of arguments, independently of the call to ldexp() - that is easier said than done. Third, you will need to handle range errors that may occur (depending on the arguments, ldexp() can trigger a range error, as the result cannot necessarily be represented in a double) and confirm that range errors are occurring whenever you expect them.

You would be better off finding some other way of determining if the function behaves as intended through some method other than testing - such as through analysis of the code used within your library to implement ldexp(). Bear in mind that the implementation of ldexp() will use other operators or machine instruction .... and your analysis will also need to determine if each one of those operators or instructions behaves as required.

Also, exp() is a function that is also declared in <cmath> (which declares ldexp()). So it is preferable that you not use a variable named exp your code, particularly if you employ "using namespace std".