blob: 493691e6f7ac20e679902fafff1e6c589d81d9b7 [file] [log] [blame]
reed@android.comed673312009-02-27 16:24:51 +00001#include "Test.h"
reed@android.comc846ede2010-04-13 15:29:15 +00002#include "SkFloatingPoint.h"
reed@android.comed673312009-02-27 16:24:51 +00003#include "SkPoint.h"
4#include "SkRandom.h"
5
6#if defined(SkLONGLONG)
7static int symmetric_fixmul(int a, int b) {
8 int sa = SkExtractSign(a);
9 int sb = SkExtractSign(b);
reed@android.com80e39a72009-04-02 16:59:40 +000010
reed@android.comed673312009-02-27 16:24:51 +000011 a = SkApplySign(a, sa);
12 b = SkApplySign(b, sb);
reed@android.com80e39a72009-04-02 16:59:40 +000013
reed@android.comed673312009-02-27 16:24:51 +000014#if 1
15 int c = (int)(((SkLONGLONG)a * b) >> 16);
reed@android.com80e39a72009-04-02 16:59:40 +000016
reed@android.comed673312009-02-27 16:24:51 +000017 return SkApplySign(c, sa ^ sb);
18#else
19 SkLONGLONG ab = (SkLONGLONG)a * b;
20 if (sa ^ sb) {
21 ab = -ab;
22 }
23 return ab >> 16;
24#endif
25}
26#endif
27
28static void check_length(skiatest::Reporter* reporter,
29 const SkPoint& p, SkScalar targetLen) {
30#ifdef SK_CAN_USE_FLOAT
31 float x = SkScalarToFloat(p.fX);
32 float y = SkScalarToFloat(p.fY);
33 float len = sk_float_sqrt(x*x + y*y);
reed@android.com80e39a72009-04-02 16:59:40 +000034
reed@android.comed673312009-02-27 16:24:51 +000035 len /= SkScalarToFloat(targetLen);
reed@android.com80e39a72009-04-02 16:59:40 +000036
reed@android.comed673312009-02-27 16:24:51 +000037 REPORTER_ASSERT(reporter, len > 0.999f && len < 1.001f);
38#endif
39}
40
41#if defined(SK_CAN_USE_FLOAT)
42
43static float nextFloat(SkRandom& rand) {
44 SkFloatIntUnion data;
45 data.fSignBitInt = rand.nextU();
46 return data.fFloat;
47}
48
49/* returns true if a == b as resulting from (int)x. Since it is undefined
50 what to do if the float exceeds 2^32-1, we check for that explicitly.
51 */
52static bool equal_float_native_skia(float x, uint32_t ni, uint32_t si) {
53 if (!(x == x)) { // NAN
54 return si == SK_MaxS32 || si == SK_MinS32;
55 }
56 // for out of range, C is undefined, but skia always should return NaN32
57 if (x > SK_MaxS32) {
58 return si == SK_MaxS32;
59 }
60 if (x < -SK_MaxS32) {
61 return si == SK_MinS32;
62 }
63 return si == ni;
64}
65
66static void assert_float_equal(skiatest::Reporter* reporter, const char op[],
67 float x, uint32_t ni, uint32_t si) {
68 if (!equal_float_native_skia(x, ni, si)) {
69 SkString desc;
70 desc.printf("%s float %g bits %x native %x skia %x\n", op, x, ni, si);
71 reporter->reportFailed(desc);
72 }
73}
74
75static void test_float_cast(skiatest::Reporter* reporter, float x) {
76 int ix = (int)x;
77 int iix = SkFloatToIntCast(x);
78 assert_float_equal(reporter, "cast", x, ix, iix);
79}
80
81static void test_float_floor(skiatest::Reporter* reporter, float x) {
82 int ix = (int)floor(x);
83 int iix = SkFloatToIntFloor(x);
84 assert_float_equal(reporter, "floor", x, ix, iix);
85}
86
87static void test_float_round(skiatest::Reporter* reporter, float x) {
88 double xx = x + 0.5; // need intermediate double to avoid temp loss
89 int ix = (int)floor(xx);
90 int iix = SkFloatToIntRound(x);
91 assert_float_equal(reporter, "round", x, ix, iix);
92}
93
94static void test_float_ceil(skiatest::Reporter* reporter, float x) {
95 int ix = (int)ceil(x);
96 int iix = SkFloatToIntCeil(x);
97 assert_float_equal(reporter, "ceil", x, ix, iix);
98}
99
100static void test_float_conversions(skiatest::Reporter* reporter, float x) {
101 test_float_cast(reporter, x);
102 test_float_floor(reporter, x);
103 test_float_round(reporter, x);
104 test_float_ceil(reporter, x);
105}
106
107static void test_int2float(skiatest::Reporter* reporter, int ival) {
108 float x0 = (float)ival;
109 float x1 = SkIntToFloatCast(ival);
110 float x2 = SkIntToFloatCast_NoOverflowCheck(ival);
111 REPORTER_ASSERT(reporter, x0 == x1);
112 REPORTER_ASSERT(reporter, x0 == x2);
113}
114
115static void unittest_fastfloat(skiatest::Reporter* reporter) {
116 SkRandom rand;
117 size_t i;
reed@android.com80e39a72009-04-02 16:59:40 +0000118
reed@android.comed673312009-02-27 16:24:51 +0000119 static const float gFloats[] = {
120 0.f, 1.f, 0.5f, 0.499999f, 0.5000001f, 1.f/3,
121 0.000000001f, 1000000000.f, // doesn't overflow
122 0.0000000001f, 10000000000.f // does overflow
123 };
124 for (i = 0; i < SK_ARRAY_COUNT(gFloats); i++) {
reed@android.comed673312009-02-27 16:24:51 +0000125 test_float_conversions(reporter, gFloats[i]);
126 test_float_conversions(reporter, -gFloats[i]);
127 }
reed@android.com80e39a72009-04-02 16:59:40 +0000128
reed@android.comed673312009-02-27 16:24:51 +0000129 for (int outer = 0; outer < 100; outer++) {
130 rand.setSeed(outer);
131 for (i = 0; i < 100000; i++) {
132 float x = nextFloat(rand);
133 test_float_conversions(reporter, x);
134 }
reed@android.com80e39a72009-04-02 16:59:40 +0000135
reed@android.comed673312009-02-27 16:24:51 +0000136 test_int2float(reporter, 0);
137 test_int2float(reporter, 1);
138 test_int2float(reporter, -1);
139 for (i = 0; i < 100000; i++) {
140 // for now only test ints that are 24bits or less, since we don't
141 // round (down) large ints the same as IEEE...
142 int ival = rand.nextU() & 0xFFFFFF;
143 test_int2float(reporter, ival);
144 test_int2float(reporter, -ival);
145 }
146 }
147}
148
reed@android.comd4134452011-02-09 02:24:26 +0000149#ifdef SK_SCALAR_IS_FLOAT
reed@google.com077910e2011-02-08 21:56:39 +0000150static float make_zero() {
151 return sk_float_sin(0);
152}
reed@android.comd4134452011-02-09 02:24:26 +0000153#endif
reed@google.com077910e2011-02-08 21:56:39 +0000154
155static void unittest_isfinite(skiatest::Reporter* reporter) {
156#ifdef SK_SCALAR_IS_FLOAT
157 float nan = ::asin(2);
158 float inf = 1.0 / make_zero();
159 float big = 3.40282e+038;
160
reed@google.com077910e2011-02-08 21:56:39 +0000161 REPORTER_ASSERT(reporter, !SkScalarIsNaN(inf));
reed@android.comd4134452011-02-09 02:24:26 +0000162 REPORTER_ASSERT(reporter, !SkScalarIsNaN(-inf));
163 REPORTER_ASSERT(reporter, !SkScalarIsFinite(inf));
164 REPORTER_ASSERT(reporter, !SkScalarIsFinite(-inf));
165#else
166 SkFixed nan = SK_FixedNaN;
167 SkFixed big = SK_FixedMax;
168#endif
169
170 REPORTER_ASSERT(reporter, SkScalarIsNaN(nan));
reed@google.com077910e2011-02-08 21:56:39 +0000171 REPORTER_ASSERT(reporter, !SkScalarIsNaN(big));
172 REPORTER_ASSERT(reporter, !SkScalarIsNaN(-big));
173 REPORTER_ASSERT(reporter, !SkScalarIsNaN(0));
reed@android.comd4134452011-02-09 02:24:26 +0000174
reed@google.com077910e2011-02-08 21:56:39 +0000175 REPORTER_ASSERT(reporter, !SkScalarIsFinite(nan));
reed@google.com077910e2011-02-08 21:56:39 +0000176 REPORTER_ASSERT(reporter, SkScalarIsFinite(big));
177 REPORTER_ASSERT(reporter, SkScalarIsFinite(-big));
178 REPORTER_ASSERT(reporter, SkScalarIsFinite(0));
reed@google.com077910e2011-02-08 21:56:39 +0000179}
180
reed@android.comed673312009-02-27 16:24:51 +0000181#endif
182
183static void test_muldiv255(skiatest::Reporter* reporter) {
184#ifdef SK_CAN_USE_FLOAT
185 for (int a = 0; a <= 255; a++) {
186 for (int b = 0; b <= 255; b++) {
187 int ab = a * b;
188 float s = ab / 255.0f;
189 int round = (int)floorf(s + 0.5f);
190 int trunc = (int)floorf(s);
reed@android.com80e39a72009-04-02 16:59:40 +0000191
reed@android.comed673312009-02-27 16:24:51 +0000192 int iround = SkMulDiv255Round(a, b);
193 int itrunc = SkMulDiv255Trunc(a, b);
reed@android.com80e39a72009-04-02 16:59:40 +0000194
reed@android.comed673312009-02-27 16:24:51 +0000195 REPORTER_ASSERT(reporter, iround == round);
196 REPORTER_ASSERT(reporter, itrunc == trunc);
reed@android.com80e39a72009-04-02 16:59:40 +0000197
reed@android.comed673312009-02-27 16:24:51 +0000198 REPORTER_ASSERT(reporter, itrunc <= iround);
199 REPORTER_ASSERT(reporter, iround <= a);
200 REPORTER_ASSERT(reporter, iround <= b);
201 }
202 }
203#endif
204}
205
senorblanco@chromium.orgec7a30c2010-12-07 21:07:56 +0000206static void test_muldiv255ceiling(skiatest::Reporter* reporter) {
207 for (int c = 0; c <= 255; c++) {
208 for (int a = 0; a <= 255; a++) {
209 int product = (c * a + 255);
210 int expected_ceiling = (product + (product >> 8)) >> 8;
211 int webkit_ceiling = (c * a + 254) / 255;
212 REPORTER_ASSERT(reporter, expected_ceiling == webkit_ceiling);
213 int skia_ceiling = SkMulDiv255Ceiling(c, a);
214 REPORTER_ASSERT(reporter, skia_ceiling == webkit_ceiling);
215 }
216 }
217}
218
reed@android.comf0ad0862010-02-09 19:18:38 +0000219static void test_copysign(skiatest::Reporter* reporter) {
220 static const int32_t gTriples[] = {
221 // x, y, expected result
222 0, 0, 0,
223 0, 1, 0,
224 0, -1, 0,
225 1, 0, 1,
226 1, 1, 1,
227 1, -1, -1,
228 -1, 0, 1,
229 -1, 1, 1,
230 -1, -1, -1,
231 };
232 for (size_t i = 0; i < SK_ARRAY_COUNT(gTriples); i += 3) {
233 REPORTER_ASSERT(reporter,
234 SkCopySign32(gTriples[i], gTriples[i+1]) == gTriples[i+2]);
235#ifdef SK_CAN_USE_FLOAT
236 float x = (float)gTriples[i];
237 float y = (float)gTriples[i+1];
238 float expected = (float)gTriples[i+2];
239 REPORTER_ASSERT(reporter, sk_float_copysign(x, y) == expected);
240#endif
241 }
242
243 SkRandom rand;
244 for (int j = 0; j < 1000; j++) {
245 int ix = rand.nextS();
246 REPORTER_ASSERT(reporter, SkCopySign32(ix, ix) == ix);
247 REPORTER_ASSERT(reporter, SkCopySign32(ix, -ix) == -ix);
248 REPORTER_ASSERT(reporter, SkCopySign32(-ix, ix) == ix);
249 REPORTER_ASSERT(reporter, SkCopySign32(-ix, -ix) == -ix);
250
251 SkScalar sx = rand.nextSScalar1();
252 REPORTER_ASSERT(reporter, SkScalarCopySign(sx, sx) == sx);
253 REPORTER_ASSERT(reporter, SkScalarCopySign(sx, -sx) == -sx);
254 REPORTER_ASSERT(reporter, SkScalarCopySign(-sx, sx) == sx);
255 REPORTER_ASSERT(reporter, SkScalarCopySign(-sx, -sx) == -sx);
256 }
257}
258
reed@android.com80e39a72009-04-02 16:59:40 +0000259static void TestMath(skiatest::Reporter* reporter) {
reed@android.comed673312009-02-27 16:24:51 +0000260 int i;
261 int32_t x;
262 SkRandom rand;
reed@android.com80e39a72009-04-02 16:59:40 +0000263
reed@android.comed673312009-02-27 16:24:51 +0000264 // these should assert
265#if 0
266 SkToS8(128);
267 SkToS8(-129);
268 SkToU8(256);
269 SkToU8(-5);
reed@android.com80e39a72009-04-02 16:59:40 +0000270
reed@android.comed673312009-02-27 16:24:51 +0000271 SkToS16(32768);
272 SkToS16(-32769);
273 SkToU16(65536);
274 SkToU16(-5);
reed@android.com80e39a72009-04-02 16:59:40 +0000275
reed@android.comed673312009-02-27 16:24:51 +0000276 if (sizeof(size_t) > 4) {
277 SkToS32(4*1024*1024);
278 SkToS32(-4*1024*1024);
279 SkToU32(5*1024*1024);
280 SkToU32(-5);
281 }
282#endif
reed@android.com80e39a72009-04-02 16:59:40 +0000283
reed@android.comed673312009-02-27 16:24:51 +0000284 test_muldiv255(reporter);
senorblanco@chromium.orgec7a30c2010-12-07 21:07:56 +0000285 test_muldiv255ceiling(reporter);
reed@android.comf0ad0862010-02-09 19:18:38 +0000286 test_copysign(reporter);
reed@android.com80e39a72009-04-02 16:59:40 +0000287
reed@android.comed673312009-02-27 16:24:51 +0000288 {
289 SkScalar x = SK_ScalarNaN;
290 REPORTER_ASSERT(reporter, SkScalarIsNaN(x));
291 }
reed@android.com80e39a72009-04-02 16:59:40 +0000292
reed@android.comed673312009-02-27 16:24:51 +0000293 for (i = 1; i <= 10; i++) {
294 x = SkCubeRootBits(i*i*i, 11);
295 REPORTER_ASSERT(reporter, x == i);
296 }
reed@android.com80e39a72009-04-02 16:59:40 +0000297
reed@android.comed673312009-02-27 16:24:51 +0000298 x = SkFixedSqrt(SK_Fixed1);
299 REPORTER_ASSERT(reporter, x == SK_Fixed1);
300 x = SkFixedSqrt(SK_Fixed1/4);
301 REPORTER_ASSERT(reporter, x == SK_Fixed1/2);
302 x = SkFixedSqrt(SK_Fixed1*4);
303 REPORTER_ASSERT(reporter, x == SK_Fixed1*2);
reed@android.com80e39a72009-04-02 16:59:40 +0000304
reed@android.comed673312009-02-27 16:24:51 +0000305 x = SkFractSqrt(SK_Fract1);
306 REPORTER_ASSERT(reporter, x == SK_Fract1);
307 x = SkFractSqrt(SK_Fract1/4);
308 REPORTER_ASSERT(reporter, x == SK_Fract1/2);
309 x = SkFractSqrt(SK_Fract1/16);
310 REPORTER_ASSERT(reporter, x == SK_Fract1/4);
reed@android.com80e39a72009-04-02 16:59:40 +0000311
reed@android.comed673312009-02-27 16:24:51 +0000312 for (i = 1; i < 100; i++) {
313 x = SkFixedSqrt(SK_Fixed1 * i * i);
314 REPORTER_ASSERT(reporter, x == SK_Fixed1 * i);
315 }
reed@android.com80e39a72009-04-02 16:59:40 +0000316
reed@android.comed673312009-02-27 16:24:51 +0000317 for (i = 0; i < 1000; i++) {
318 int value = rand.nextS16();
319 int max = rand.nextU16();
reed@android.com80e39a72009-04-02 16:59:40 +0000320
reed@android.comed673312009-02-27 16:24:51 +0000321 int clamp = SkClampMax(value, max);
322 int clamp2 = value < 0 ? 0 : (value > max ? max : value);
323 REPORTER_ASSERT(reporter, clamp == clamp2);
324 }
reed@android.com80e39a72009-04-02 16:59:40 +0000325
reed@android.come72fee52009-11-16 14:52:01 +0000326 for (i = 0; i < 10000; i++) {
reed@android.comed673312009-02-27 16:24:51 +0000327 SkPoint p;
reed@android.com80e39a72009-04-02 16:59:40 +0000328
reed@android.comed673312009-02-27 16:24:51 +0000329 p.setLength(rand.nextS(), rand.nextS(), SK_Scalar1);
330 check_length(reporter, p, SK_Scalar1);
331 p.setLength(rand.nextS() >> 13, rand.nextS() >> 13, SK_Scalar1);
332 check_length(reporter, p, SK_Scalar1);
333 }
reed@android.com80e39a72009-04-02 16:59:40 +0000334
reed@android.comed673312009-02-27 16:24:51 +0000335 {
336 SkFixed result = SkFixedDiv(100, 100);
337 REPORTER_ASSERT(reporter, result == SK_Fixed1);
338 result = SkFixedDiv(1, SK_Fixed1);
339 REPORTER_ASSERT(reporter, result == 1);
340 }
reed@android.com80e39a72009-04-02 16:59:40 +0000341
reed@android.comed673312009-02-27 16:24:51 +0000342#ifdef SK_CAN_USE_FLOAT
343 unittest_fastfloat(reporter);
reed@google.com077910e2011-02-08 21:56:39 +0000344 unittest_isfinite(reporter);
reed@android.comed673312009-02-27 16:24:51 +0000345#endif
reed@android.com80e39a72009-04-02 16:59:40 +0000346
reed@android.comed673312009-02-27 16:24:51 +0000347#ifdef SkLONGLONG
reed@android.come72fee52009-11-16 14:52:01 +0000348 for (i = 0; i < 10000; i++) {
reed@android.comed673312009-02-27 16:24:51 +0000349 SkFixed numer = rand.nextS();
350 SkFixed denom = rand.nextS();
351 SkFixed result = SkFixedDiv(numer, denom);
352 SkLONGLONG check = ((SkLONGLONG)numer << 16) / denom;
reed@android.com80e39a72009-04-02 16:59:40 +0000353
reed@android.comed673312009-02-27 16:24:51 +0000354 (void)SkCLZ(numer);
355 (void)SkCLZ(denom);
reed@android.com80e39a72009-04-02 16:59:40 +0000356
reed@android.comed673312009-02-27 16:24:51 +0000357 REPORTER_ASSERT(reporter, result != (SkFixed)SK_NaN32);
358 if (check > SK_MaxS32) {
359 check = SK_MaxS32;
360 } else if (check < -SK_MaxS32) {
361 check = SK_MinS32;
362 }
363 REPORTER_ASSERT(reporter, result == (int32_t)check);
reed@android.com80e39a72009-04-02 16:59:40 +0000364
reed@android.comed673312009-02-27 16:24:51 +0000365 result = SkFractDiv(numer, denom);
366 check = ((SkLONGLONG)numer << 30) / denom;
reed@android.com80e39a72009-04-02 16:59:40 +0000367
reed@android.comed673312009-02-27 16:24:51 +0000368 REPORTER_ASSERT(reporter, result != (SkFixed)SK_NaN32);
369 if (check > SK_MaxS32) {
370 check = SK_MaxS32;
371 } else if (check < -SK_MaxS32) {
372 check = SK_MinS32;
373 }
374 REPORTER_ASSERT(reporter, result == (int32_t)check);
reed@android.com80e39a72009-04-02 16:59:40 +0000375
reed@android.comed673312009-02-27 16:24:51 +0000376 // make them <= 2^24, so we don't overflow in fixmul
377 numer = numer << 8 >> 8;
378 denom = denom << 8 >> 8;
reed@android.com80e39a72009-04-02 16:59:40 +0000379
reed@android.comed673312009-02-27 16:24:51 +0000380 result = SkFixedMul(numer, denom);
381 SkFixed r2 = symmetric_fixmul(numer, denom);
382 // SkASSERT(result == r2);
reed@android.com80e39a72009-04-02 16:59:40 +0000383
reed@android.comed673312009-02-27 16:24:51 +0000384 result = SkFixedMul(numer, numer);
385 r2 = SkFixedSquare(numer);
386 REPORTER_ASSERT(reporter, result == r2);
reed@android.com80e39a72009-04-02 16:59:40 +0000387
reed@android.comed673312009-02-27 16:24:51 +0000388#ifdef SK_CAN_USE_FLOAT
389 if (numer >= 0 && denom >= 0) {
390 SkFixed mean = SkFixedMean(numer, denom);
reed@android.com80e39a72009-04-02 16:59:40 +0000391 float prod = SkFixedToFloat(numer) * SkFixedToFloat(denom);
392 float fm = sk_float_sqrt(sk_float_abs(prod));
reed@android.comed673312009-02-27 16:24:51 +0000393 SkFixed mean2 = SkFloatToFixed(fm);
394 int diff = SkAbs32(mean - mean2);
395 REPORTER_ASSERT(reporter, diff <= 1);
396 }
reed@android.com80e39a72009-04-02 16:59:40 +0000397
reed@android.comed673312009-02-27 16:24:51 +0000398 {
399 SkFixed mod = SkFixedMod(numer, denom);
400 float n = SkFixedToFloat(numer);
401 float d = SkFixedToFloat(denom);
402 float m = sk_float_mod(n, d);
reed@android.com80e39a72009-04-02 16:59:40 +0000403 // ensure the same sign
404 REPORTER_ASSERT(reporter, mod == 0 || (mod < 0) == (m < 0));
reed@android.comed673312009-02-27 16:24:51 +0000405 int diff = SkAbs32(mod - SkFloatToFixed(m));
406 REPORTER_ASSERT(reporter, (diff >> 7) == 0);
407 }
408#endif
409 }
410#endif
reed@android.com80e39a72009-04-02 16:59:40 +0000411
reed@android.comed673312009-02-27 16:24:51 +0000412#ifdef SK_CAN_USE_FLOAT
reed@android.come72fee52009-11-16 14:52:01 +0000413 for (i = 0; i < 10000; i++) {
reed@android.comed673312009-02-27 16:24:51 +0000414 SkFract x = rand.nextU() >> 1;
415 double xx = (double)x / SK_Fract1;
416 SkFract xr = SkFractSqrt(x);
417 SkFract check = SkFloatToFract(sqrt(xx));
reed@android.com80e39a72009-04-02 16:59:40 +0000418 REPORTER_ASSERT(reporter, xr == check ||
419 xr == check-1 ||
420 xr == check+1);
421
reed@android.comed673312009-02-27 16:24:51 +0000422 xr = SkFixedSqrt(x);
423 xx = (double)x / SK_Fixed1;
424 check = SkFloatToFixed(sqrt(xx));
425 REPORTER_ASSERT(reporter, xr == check || xr == check-1);
reed@android.com80e39a72009-04-02 16:59:40 +0000426
reed@android.comed673312009-02-27 16:24:51 +0000427 xr = SkSqrt32(x);
428 xx = (double)x;
429 check = (int32_t)sqrt(xx);
430 REPORTER_ASSERT(reporter, xr == check || xr == check-1);
431 }
432#endif
reed@android.com80e39a72009-04-02 16:59:40 +0000433
reed@android.comed673312009-02-27 16:24:51 +0000434#if !defined(SK_SCALAR_IS_FLOAT) && defined(SK_CAN_USE_FLOAT)
435 {
436 SkFixed s, c;
437 s = SkFixedSinCos(0, &c);
438 REPORTER_ASSERT(reporter, s == 0);
439 REPORTER_ASSERT(reporter, c == SK_Fixed1);
440 }
reed@android.com80e39a72009-04-02 16:59:40 +0000441
reed@android.comed673312009-02-27 16:24:51 +0000442 int maxDiff = 0;
reed@android.come72fee52009-11-16 14:52:01 +0000443 for (i = 0; i < 1000; i++) {
reed@android.comed673312009-02-27 16:24:51 +0000444 SkFixed rads = rand.nextS() >> 10;
445 double frads = SkFixedToFloat(rads);
reed@android.com80e39a72009-04-02 16:59:40 +0000446
reed@android.comed673312009-02-27 16:24:51 +0000447 SkFixed s, c;
448 s = SkScalarSinCos(rads, &c);
reed@android.com80e39a72009-04-02 16:59:40 +0000449
reed@android.comed673312009-02-27 16:24:51 +0000450 double fs = sin(frads);
451 double fc = cos(frads);
reed@android.com80e39a72009-04-02 16:59:40 +0000452
reed@android.comed673312009-02-27 16:24:51 +0000453 SkFixed is = SkFloatToFixed(fs);
454 SkFixed ic = SkFloatToFixed(fc);
reed@android.com80e39a72009-04-02 16:59:40 +0000455
reed@android.comed673312009-02-27 16:24:51 +0000456 maxDiff = SkMax32(maxDiff, SkAbs32(is - s));
457 maxDiff = SkMax32(maxDiff, SkAbs32(ic - c));
458 }
459 SkDebugf("SinCos: maximum error = %d\n", maxDiff);
460#endif
461}
462
reed@android.comd8730ea2009-02-27 22:06:06 +0000463#include "TestClassDef.h"
464DEFINE_TESTCLASS("Math", MathTestClass, TestMath)