/tools/regression/lib/msun/test-conj.c

https://bitbucket.org/iorivur/freebsd-bhyve-with-suspend-resume · C · 139 lines · 94 code · 15 blank · 30 comment · 13 complexity · 689c4ebc19a4d38cdb310e280816f020 MD5 · raw file

  1. /*-
  2. * Copyright (c) 2008 David Schultz <das@FreeBSD.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. */
  26. /*
  27. * Tests for conj{,f,l}()
  28. */
  29. #include <sys/cdefs.h>
  30. __FBSDID("$FreeBSD: head/tools/regression/lib/msun/test-conj.c 251241 2013-06-02 04:30:03Z das $");
  31. #include <assert.h>
  32. #include <complex.h>
  33. #include <fenv.h>
  34. #include <math.h>
  35. #include <stdio.h>
  36. #include "test-utils.h"
  37. #pragma STDC CX_LIMITED_RANGE off
  38. /* Make sure gcc doesn't use builtin versions of these or honor __pure2. */
  39. static float complex (*libconjf)(float complex) = conjf;
  40. static double complex (*libconj)(double complex) = conj;
  41. static long double complex (*libconjl)(long double complex) = conjl;
  42. static float (*libcrealf)(float complex) = crealf;
  43. static double (*libcreal)(double complex) = creal;
  44. static long double (*libcreall)(long double complex) = creall;
  45. static float (*libcimagf)(float complex) = cimagf;
  46. static double (*libcimag)(double complex) = cimag;
  47. static long double (*libcimagl)(long double complex) = cimagl;
  48. static const double tests[] = {
  49. /* a + bI */
  50. 0.0, 0.0,
  51. 0.0, 1.0,
  52. 1.0, 0.0,
  53. -1.0, 0.0,
  54. 1.0, -0.0,
  55. 0.0, -1.0,
  56. 2.0, 4.0,
  57. 0.0, INFINITY,
  58. 0.0, -INFINITY,
  59. INFINITY, 0.0,
  60. NAN, 1.0,
  61. 1.0, NAN,
  62. NAN, NAN,
  63. -INFINITY, INFINITY,
  64. };
  65. int
  66. main(int argc, char *argv[])
  67. {
  68. static const int ntests = sizeof(tests) / sizeof(tests[0]) / 2;
  69. complex float in;
  70. complex long double expected;
  71. int i;
  72. printf("1..%d\n", ntests * 3);
  73. for (i = 0; i < ntests; i++) {
  74. __real__ expected = __real__ in = tests[2 * i];
  75. __imag__ in = tests[2 * i + 1];
  76. __imag__ expected = -cimag(in);
  77. assert(fpequal(libcrealf(in), __real__ in));
  78. assert(fpequal(libcreal(in), __real__ in));
  79. assert(fpequal(libcreall(in), __real__ in));
  80. assert(fpequal(libcimagf(in), __imag__ in));
  81. assert(fpequal(libcimag(in), __imag__ in));
  82. assert(fpequal(libcimagl(in), __imag__ in));
  83. feclearexcept(FE_ALL_EXCEPT);
  84. if (!cfpequal(libconjf(in), expected)) {
  85. printf("not ok %d\t# conjf(%#.2g + %#.2gI): "
  86. "wrong value\n",
  87. 3 * i + 1, creal(in), cimag(in));
  88. } else if (fetestexcept(FE_ALL_EXCEPT)) {
  89. printf("not ok %d\t# conjf(%#.2g + %#.2gI): "
  90. "threw an exception\n",
  91. 3 * i + 1, creal(in), cimag(in));
  92. } else {
  93. printf("ok %d\t\t# conjf(%#.2g + %#.2gI)\n",
  94. 3 * i + 1, creal(in), cimag(in));
  95. }
  96. feclearexcept(FE_ALL_EXCEPT);
  97. if (!cfpequal(libconj(in), expected)) {
  98. printf("not ok %d\t# conj(%#.2g + %#.2gI): "
  99. "wrong value\n",
  100. 3 * i + 2, creal(in), cimag(in));
  101. } else if (fetestexcept(FE_ALL_EXCEPT)) {
  102. printf("not ok %d\t# conj(%#.2g + %#.2gI): "
  103. "threw an exception\n",
  104. 3 * i + 2, creal(in), cimag(in));
  105. } else {
  106. printf("ok %d\t\t# conj(%#.2g + %#.2gI)\n",
  107. 3 * i + 2, creal(in), cimag(in));
  108. }
  109. feclearexcept(FE_ALL_EXCEPT);
  110. if (!cfpequal(libconjl(in), expected)) {
  111. printf("not ok %d\t# conjl(%#.2g + %#.2gI): "
  112. "wrong value\n",
  113. 3 * i + 3, creal(in), cimag(in));
  114. } else if (fetestexcept(FE_ALL_EXCEPT)) {
  115. printf("not ok %d\t# conjl(%#.2g + %#.2gI): "
  116. "threw an exception\n",
  117. 3 * i + 3, creal(in), cimag(in));
  118. } else {
  119. printf("ok %d\t\t# conjl(%#.2g + %#.2gI)\n",
  120. 3 * i + 3, creal(in), cimag(in));
  121. }
  122. }
  123. return (0);
  124. }