source: CIVL/examples/complex/complex_basics.c

main
Last change on this file was 05a4f7e, checked in by Stephen Siegel <siegel@…>, 18 hours ago

Added support for "floor", which is now supported by SMT-LIB2.
Fixed simple bug in transformation: in MPI transformer, math.h was being
moved to file scope, but not math.cvl. Now it is, and the one MPI prime
test that was failing now passes.

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include <assert.h>
2#include <complex.h>
3#include <stdbool.h>
4
5double _Complex x = 1 + 2.0i;
6
7int main(void) {
8 assert(x == 1 + 2.i);
9 assert(x == 1 + 2*I);
10 assert(x == 1 + 2*_Complex_I);
11 assert(x == CMPLX(1.0, 2.0));
12 assert(creal(x) == 1.0);
13 assert(cimag(x) == 2.0);
14 assert(x);
15 assert(x!=0);
16 assert(2*x == 2 + 4.0i);
17
18 // Check implicit conversions to _Bool...
19 double _Complex y1 = 3.14;
20 double _Complex y2 = 3.14i;
21 double _Complex y3 = 0;
22 if (y1)
23 assert(true);
24 else
25 assert(false);
26 if (y2)
27 assert(true);
28 else
29 assert(false);
30 if (y3)
31 assert(false);
32 else
33 assert(true);
34 while (y3) {
35 assert(false);
36 }
37
38 // Check other conversions...
39 float _Complex x_f = x;
40 assert(x_f == 1.0f + 2.if);
41 assert(crealf(x_f) == 1.0f);
42 assert(cimagf(x_f) == 2.0f);
43 assert(x_f == CMPLXF(1, 2));
44 double a = x;
45 assert(a==1);
46 long double _Complex x_l = x;
47 assert(x_l == (long double)1.0 + ((long double)2.0)*I);
48
49 // Qualifiers...
50 const double _Complex z = CMPLX(3.333, -2.222);
51 assert(creal(z) == 3.333);
52 assert(cimag(z) == -2.222);
53}
Note: See TracBrowser for help on using the repository browser.