OLD | NEW |
1 // from http://tog.acm.org/resources/GraphicsGems/gems/Roots3And4.c | 1 // from http://tog.acm.org/resources/GraphicsGems/gems/Roots3And4.c |
2 /* | 2 /* |
3 * Roots3And4.c | 3 * Roots3And4.c |
4 * | 4 * |
5 * Utility functions to find cubic and quartic roots, | 5 * Utility functions to find cubic and quartic roots, |
6 * coefficients are passed like this: | 6 * coefficients are passed like this: |
7 * | 7 * |
8 * c[0] + c[1]*x + c[2]*x^2 + c[3]*x^3 + c[4]*x^4 = 0 | 8 * c[0] + c[1]*x + c[2]*x^2 + c[3]*x^3 + c[4]*x^4 = 0 |
9 * | 9 * |
10 * The functions return the number of non-complex roots and | 10 * The functions return the number of non-complex roots and |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 } | 146 } |
147 /* resubstitute */ | 147 /* resubstitute */ |
148 const double sub = a / 4; | 148 const double sub = a / 4; |
149 for (int i = 0; i < num; ++i) { | 149 for (int i = 0; i < num; ++i) { |
150 s[i] -= sub; | 150 s[i] -= sub; |
151 } | 151 } |
152 // eliminate duplicates | 152 // eliminate duplicates |
153 for (int i = 0; i < num - 1; ++i) { | 153 for (int i = 0; i < num - 1; ++i) { |
154 for (int j = i + 1; j < num; ) { | 154 for (int j = i + 1; j < num; ) { |
155 if (AlmostEqualUlps(s[i], s[j])) { | 155 if (AlmostDequalUlps(s[i], s[j])) { |
156 if (j < --num) { | 156 if (j < --num) { |
157 s[j] = s[num]; | 157 s[j] = s[num]; |
158 } | 158 } |
159 } else { | 159 } else { |
160 ++j; | 160 ++j; |
161 } | 161 } |
162 } | 162 } |
163 } | 163 } |
164 return num; | 164 return num; |
165 } | 165 } |
OLD | NEW |