Let me guess:
First, you determined that the problem is in the loop, and you only use the following operations: + , * , / .
The rules for generating NaN from these operations are:
- Sections
0/0 and ยฑโ/ยฑโ - Multiplications
0รยฑโ and ยฑโร0 - Additions
โ + (โโ) , (โโ) + โ and equivalent subtractions
You have ruled out the possibility of 0/0 and ยฑโ/ยฑโ , indicating that faculty[] correctly initialized.
The sign variable is always 1.0 or -1.0 , so it cannot generate a NaN operation via * .
Operation + remains if tempExp ever became ยฑโ .
Thus, it is likely that tempExp too high when entering your function and becomes ยฑโ , this will make sum equal to ยฑโ . At the next iteration, you initiate the NaN generation operation with: โ + (โโ) . This is due to the fact that you multiply one side of addition by sign and at each iteration you can switch between positive and negative.
You are trying to bring cos(x) around 0.0 . Therefore, you should use the properties of the cos() function to reduce your input value to around 0.0 . Ideal in the range [0, pi/4] . For example, remove the 2*pi multiplicity and get the cos() values โโin [pi/4, pi/2] , calculating sin(x) around 0.0 , etc.
fjardon
source share