I am programming vector calculator and it needs to test for a certain set of conditions. I thought maybe someone familiar with this kind of statement could give me a little feedback.

Here is what I have so far (2 conditions):

=IF(D9>90, D8*COS(D9-90)*PI()/180, IF(D9>180,D8*COS(D9-180)*PI()/180, D8*COS(D9)*PI()/180))

The 2 conditions are to subtract 90 from d9 if its greater then 90 (within the formula and then the subtract 180 from D9 if it is greater then 180 else just do the normal formula.
Maybe there is something obvious I am missing. Any feedback would be greatly appreciated.
thank you very much.