| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "TestClassDef.h" | 9 #include "TestClassDef.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 for (i = 0; i < 100000; i++) { | 321 for (i = 0; i < 100000; i++) { |
| 322 // for now only test ints that are 24bits or less, since we don't | 322 // for now only test ints that are 24bits or less, since we don't |
| 323 // round (down) large ints the same as IEEE... | 323 // round (down) large ints the same as IEEE... |
| 324 int ival = rand.nextU() & 0xFFFFFF; | 324 int ival = rand.nextU() & 0xFFFFFF; |
| 325 test_int2float(reporter, ival); | 325 test_int2float(reporter, ival); |
| 326 test_int2float(reporter, -ival); | 326 test_int2float(reporter, -ival); |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 | 330 |
| 331 #ifdef SK_SCALAR_IS_FLOAT | |
| 332 static float make_zero() { | 331 static float make_zero() { |
| 333 return sk_float_sin(0); | 332 return sk_float_sin(0); |
| 334 } | 333 } |
| 335 #endif | |
| 336 | 334 |
| 337 static void unittest_isfinite(skiatest::Reporter* reporter) { | 335 static void unittest_isfinite(skiatest::Reporter* reporter) { |
| 338 #ifdef SK_SCALAR_IS_FLOAT | |
| 339 float nan = sk_float_asin(2); | 336 float nan = sk_float_asin(2); |
| 340 float inf = 1.0f / make_zero(); | 337 float inf = 1.0f / make_zero(); |
| 341 float big = 3.40282e+038f; | 338 float big = 3.40282e+038f; |
| 342 | 339 |
| 343 REPORTER_ASSERT(reporter, !SkScalarIsNaN(inf)); | 340 REPORTER_ASSERT(reporter, !SkScalarIsNaN(inf)); |
| 344 REPORTER_ASSERT(reporter, !SkScalarIsNaN(-inf)); | 341 REPORTER_ASSERT(reporter, !SkScalarIsNaN(-inf)); |
| 345 REPORTER_ASSERT(reporter, !SkScalarIsFinite(inf)); | 342 REPORTER_ASSERT(reporter, !SkScalarIsFinite(inf)); |
| 346 REPORTER_ASSERT(reporter, !SkScalarIsFinite(-inf)); | 343 REPORTER_ASSERT(reporter, !SkScalarIsFinite(-inf)); |
| 347 #else | |
| 348 SkFixed nan = SK_FixedNaN; | |
| 349 SkFixed big = SK_FixedMax; | |
| 350 #endif | |
| 351 | 344 |
| 352 REPORTER_ASSERT(reporter, SkScalarIsNaN(nan)); | 345 REPORTER_ASSERT(reporter, SkScalarIsNaN(nan)); |
| 353 REPORTER_ASSERT(reporter, !SkScalarIsNaN(big)); | 346 REPORTER_ASSERT(reporter, !SkScalarIsNaN(big)); |
| 354 REPORTER_ASSERT(reporter, !SkScalarIsNaN(-big)); | 347 REPORTER_ASSERT(reporter, !SkScalarIsNaN(-big)); |
| 355 REPORTER_ASSERT(reporter, !SkScalarIsNaN(0)); | 348 REPORTER_ASSERT(reporter, !SkScalarIsNaN(0)); |
| 356 | 349 |
| 357 REPORTER_ASSERT(reporter, !SkScalarIsFinite(nan)); | 350 REPORTER_ASSERT(reporter, !SkScalarIsFinite(nan)); |
| 358 REPORTER_ASSERT(reporter, SkScalarIsFinite(big)); | 351 REPORTER_ASSERT(reporter, SkScalarIsFinite(big)); |
| 359 REPORTER_ASSERT(reporter, SkScalarIsFinite(-big)); | 352 REPORTER_ASSERT(reporter, SkScalarIsFinite(-big)); |
| 360 REPORTER_ASSERT(reporter, SkScalarIsFinite(0)); | 353 REPORTER_ASSERT(reporter, SkScalarIsFinite(0)); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 xx = (double)x / SK_Fixed1; | 593 xx = (double)x / SK_Fixed1; |
| 601 check = SkFloatToFixed(sqrt(xx)); | 594 check = SkFloatToFixed(sqrt(xx)); |
| 602 REPORTER_ASSERT(reporter, xr == check || xr == check-1); | 595 REPORTER_ASSERT(reporter, xr == check || xr == check-1); |
| 603 | 596 |
| 604 xr = SkSqrt32(x); | 597 xr = SkSqrt32(x); |
| 605 xx = (double)x; | 598 xx = (double)x; |
| 606 check = (int32_t)sqrt(xx); | 599 check = (int32_t)sqrt(xx); |
| 607 REPORTER_ASSERT(reporter, xr == check || xr == check-1); | 600 REPORTER_ASSERT(reporter, xr == check || xr == check-1); |
| 608 } | 601 } |
| 609 | 602 |
| 610 #if !defined(SK_SCALAR_IS_FLOAT) | |
| 611 { | |
| 612 SkFixed s, c; | |
| 613 s = SkFixedSinCos(0, &c); | |
| 614 REPORTER_ASSERT(reporter, s == 0); | |
| 615 REPORTER_ASSERT(reporter, c == SK_Fixed1); | |
| 616 } | |
| 617 | |
| 618 int maxDiff = 0; | |
| 619 for (i = 0; i < 1000; i++) { | |
| 620 SkFixed rads = rand.nextS() >> 10; | |
| 621 double frads = SkFixedToFloat(rads); | |
| 622 | |
| 623 SkFixed s, c; | |
| 624 s = SkScalarSinCos(rads, &c); | |
| 625 | |
| 626 double fs = sin(frads); | |
| 627 double fc = cos(frads); | |
| 628 | |
| 629 SkFixed is = SkFloatToFixed(fs); | |
| 630 SkFixed ic = SkFloatToFixed(fc); | |
| 631 | |
| 632 maxDiff = SkMax32(maxDiff, SkAbs32(is - s)); | |
| 633 maxDiff = SkMax32(maxDiff, SkAbs32(ic - c)); | |
| 634 } | |
| 635 SkDebugf("SinCos: maximum error = %d\n", maxDiff); | |
| 636 #endif | |
| 637 | |
| 638 #ifdef SK_SCALAR_IS_FLOAT | |
| 639 test_blend(reporter); | 603 test_blend(reporter); |
| 640 #endif | |
| 641 | 604 |
| 642 if (false) test_floor(reporter); | 605 if (false) test_floor(reporter); |
| 643 | 606 |
| 644 // disable for now | 607 // disable for now |
| 645 if (false) test_blend31(); // avoid bit rot, suppress warning | 608 if (false) test_blend31(); // avoid bit rot, suppress warning |
| 646 | 609 |
| 647 test_muldivround(reporter); | 610 test_muldivround(reporter); |
| 648 test_clz(reporter); | 611 test_clz(reporter); |
| 649 } | 612 } |
| 650 | 613 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 test_divmod<int16_t>(r); | 711 test_divmod<int16_t>(r); |
| 749 } | 712 } |
| 750 | 713 |
| 751 DEF_TEST(divmod_s32, r) { | 714 DEF_TEST(divmod_s32, r) { |
| 752 test_divmod<int32_t>(r); | 715 test_divmod<int32_t>(r); |
| 753 } | 716 } |
| 754 | 717 |
| 755 DEF_TEST(divmod_s64, r) { | 718 DEF_TEST(divmod_s64, r) { |
| 756 test_divmod<int64_t>(r); | 719 test_divmod<int64_t>(r); |
| 757 } | 720 } |
| OLD | NEW |