testClamp.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function equal(a, b) {
  6. if (a == b)
  7. {
  8. print("Correct");
  9. }
  10. else
  11. {
  12. print(">> Fail!");
  13. }
  14. }
  15. function testClamp() {
  16. print("Float32x4 clamp");
  17. var a = SIMD.Float32x4(-20.0, 10.0, 30.0, 0.5);
  18. var lower = SIMD.Float32x4(2.0, 1.0, 50.0, 0.0);
  19. var upper = SIMD.Float32x4(2.5, 5.0, 55.0, 1.0);
  20. var c = SIMD.Float32x4.clamp(a, lower, upper);
  21. equal(2.0, SIMD.Float32x4.extractLane(c, 0));
  22. equal(5.0, SIMD.Float32x4.extractLane(c, 1));
  23. equal(50.0, SIMD.Float32x4.extractLane(c, 2));
  24. equal(0.5, SIMD.Float32x4.extractLane(c, 3));
  25. }
  26. testClamp();
  27. testClamp();
  28. testClamp();
  29. testClamp();
  30. testClamp();
  31. testClamp();
  32. testClamp();
  33. testClamp();