source: CIVL/examples/complex/complex_basics.c@ 478ca9e

2.0 acw/focus-triggers main
Last change on this file since 478ca9e was 478ca9e, checked in by Stephen Siegel <siegel@…>, 2 weeks ago

Working on Complex Transformer. A few remnants of the $state type found
and being deleted.

  • Property mode set to 100644
File size: 968 bytes
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}
Note: See TracBrowser for help on using the repository browser.