Skip to content

Commit e4c23d1

Browse files
committed
add test for copysign of negative zero
1 parent 989e8dd commit e4c23d1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tests/core/test_negative_zero.in

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
#include <stdio.h>
22
#include <math.h>
33

4+
// test copysign of 0
5+
int __attribute__((noinline,noclone))
6+
copysign_bug (double x)
7+
{
8+
if (x != 0.0 && (x * 0.5 == x)) {
9+
printf("1\n");
10+
return 1;
11+
}
12+
printf("f: %f\n", x);
13+
if (__builtin_copysign(1.0, x) < 0.0) {
14+
printf("2\n");
15+
return 2;
16+
} else {
17+
printf("3\n");
18+
return 3;
19+
}
20+
}
21+
422
int main() {
523
#define TEST(x, y) printf("%.2f, %.2f ==> %.2f\n", x, y, copysign(x, y));
624
TEST(5.0f, 5.0f);
@@ -23,5 +41,10 @@ int main() {
2341
TEST(0.0f, -0.0f);
2442
TEST(-0.0f, 0.0f);
2543
TEST(-0.0f, -0.0f);
44+
45+
double x = -0.0;
46+
if (copysign_bug (x) != 2)
47+
__builtin_abort ();
48+
2649
return 0;
2750
}

tests/core/test_negative_zero.out

+2
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
0.00, -0.00 ==> -0.00
1919
-0.00, 0.00 ==> 0.00
2020
-0.00, -0.00 ==> -0.00
21+
f: -0.000000
22+
2

0 commit comments

Comments
 (0)