Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.7 KiB

  1. #include <stdio.h>
  2. #include <math.h>
  3. /*
  4. * During the development of OpenGL on NT, we have had problems
  5. * with the compiler and floating point. Here are a few simple
  6. * sanity checks to make sure the compiler didn't regress.
  7. */
  8. #define POW_TEST \
  9. /* pow(0,0) should be 1 not 0 */ \
  10. f = (float)pow(0.0, 0.0); \
  11. printf("pow(0.0, 0.0) is %f ", f); \
  12. if (f == 1.0F) { \
  13. printf("Correct\n"); \
  14. } else { \
  15. printf("ERROR\n"); \
  16. errorcount++; \
  17. }
  18. #define FLOOR_TEST \
  19. /* floor() would always return 0! */ \
  20. d = floor(8.123); \
  21. printf("floor(8.123) is %lf ", d); \
  22. if (d == 8.0) { \
  23. printf("Correct\n"); \
  24. } else { \
  25. printf("ERROR\n"); \
  26. errorcount++; \
  27. } \
  28. d = floor(63.5); \
  29. printf("floor(63.5) is %lf ", d); \
  30. if (d == 63.0) { \
  31. printf("Correct\n"); \
  32. } else { \
  33. printf("ERROR\n"); \
  34. errorcount++; \
  35. }
  36. int nointrin(void);
  37. int CastTest(void);
  38. main()
  39. {
  40. float f;
  41. double d;
  42. int errorcount = 0;
  43. f = (float)pow(0.0, 3.0);
  44. if (f != 0.0F) {
  45. printf("pow(0.0, 3.0) not 0.0! ERROR\n");
  46. errorcount++;
  47. } else {
  48. printf("pow(0.0, 3.0) is 0.0 Correct\n");
  49. }
  50. POW_TEST;
  51. FLOOR_TEST;
  52. errorcount += CastTest();
  53. errorcount += nointrin();
  54. if (errorcount)
  55. printf("%d errors in test\n", errorcount);
  56. else
  57. printf("\nAll tests passed\n");
  58. return errorcount;
  59. }
  60. int
  61. CastTest()
  62. {
  63. double dMaxUint;
  64. unsigned int uiResult;
  65. dMaxUint = 4294967295.0;
  66. uiResult = (unsigned int)dMaxUint;
  67. printf("uiResult(0x%08lX) = (unsigned int)dMaxUint(%lf) ",
  68. uiResult, dMaxUint);
  69. if (uiResult == 0xffffffff) {
  70. printf("Correct\n");
  71. return 0;
  72. } else {
  73. printf("ERROR\n");
  74. return 1;
  75. }
  76. }
  77. #pragma function (pow)
  78. #pragma function (floor)
  79. int
  80. nointrin()
  81. {
  82. float f;
  83. double d;
  84. int errorcount = 0;
  85. printf("\n\nNot using intrinsic functions for:\n");
  86. printf("pow()\n");
  87. printf("floor()\n");
  88. printf("\n");
  89. POW_TEST;
  90. FLOOR_TEST;
  91. return errorcount;
  92. }