]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/runnable/test22.d
d: Synchronize testsuite with upstream dmd
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / runnable / test22.d
1 // RUNNABLE_PHOBOS_TEST
2 // REQUIRED_ARGS:
3
4 import std.math: poly;
5 import core.stdc.stdarg;
6
7 extern(C)
8 {
9 int printf(const char*, ...);
10 version(Windows)
11 {
12 int _snprintf(char*, size_t, const char*, ...);
13 alias _snprintf snprintf;
14 }
15 else
16 int snprintf(char*, size_t, const char*, ...);
17 }
18
19 /*************************************/
20
21 // http://www.digitalmars.com/d/archives/digitalmars/D/bugs/4766.html
22 // Only with -O
23
24 real randx()
25 {
26 return 1.2;
27 }
28
29 void test1()
30 {
31 float x10=randx();
32 float x11=randx();
33 float x20=randx();
34 float x21=randx();
35 float y10=randx();
36 float y11=randx();
37 float y20=randx();
38 float y21=randx();
39
40 float tmp=(
41 x20*x21 + y10*y10 + y10*y11 + y11*y11 +
42 y11*y20 + y20*y20 + y10*y21 + y11*y21 +
43 y21*y21);
44 assert(tmp > 0);
45 }
46
47 /*************************************/
48
49 void test2()
50 {
51 double x10=randx();
52 double x11=randx();
53 double x20=randx();
54 double x21=randx();
55 double y10=randx();
56 double y11=randx();
57 double y20=randx();
58 double y21=randx();
59
60 double tmp=(
61 x20*x21 + y10*y10 + y10*y11 + y11*y11 +
62 y11*y20 + y20*y20 + y10*y21 + y11*y21 +
63 y21*y21);
64 assert(tmp > 0);
65 }
66
67 /*************************************/
68
69 void test3()
70 {
71 real x10=randx();
72 real x11=randx();
73 real x20=randx();
74 real x21=randx();
75 real y10=randx();
76 real y11=randx();
77 real y20=randx();
78 real y21=randx();
79
80 real tmp=(
81 x20*x21 + y10*y10 + y10*y11 + y11*y11 +
82 y11*y20 + y20*y20 + y10*y21 + y11*y21 +
83 y21*y21);
84 assert(tmp > 0);
85 }
86
87 /*************************************/
88
89 void test4()
90 {
91 printf("main() : (-128 >= 0)=%s, (-128 <= 0)=%s\n",
92 cast(char*)(-128 >= 0 ? "true" : "false"),
93 cast(char*)(-128 <= 0 ? "true" : "false"));
94
95 printf("main() : (128 >= 0)=%s, (128 <= 0)=%s\n",
96 cast(char*)(128 >= 0 ? "true" : "false"),
97 cast(char*)(128 <= 0 ? "true" : "false"));
98
99 assert((-128 >= 0 ? "true" : "false") == "false"),
100 assert((-128 <= 0 ? "true" : "false") == "true");
101 assert((+128 >= 0 ? "true" : "false") == "true"),
102 assert((+128 <= 0 ? "true" : "false") == "false");
103 }
104
105
106 /*************************************/
107
108 int foo5() { assert(0); } // No return.
109
110 int abc5()
111 {
112 printf("foo = %d\n", foo5());
113 return 0;
114 }
115
116 void test5()
117 {
118 }
119
120 /*************************************/
121
122 void test6()
123 {
124 ireal a = 6.5i % 3i;
125 printf("%Lfi %Lfi\n", a, a - .5i);
126 assert(a == .5i);
127
128 a = 6.5i % 3;
129 printf("%Lfi %Lfi\n", a, a - .5i);
130 assert(a == .5i);
131
132 real b = 6.5 % 3i;
133 printf("%Lf %Lf\n", b, b - .5);
134 assert(b == .5);
135
136 b = 6.5 % 3;
137 printf("%Lf %Lf\n", b, b - .5);
138 assert(b == .5);
139 }
140
141 /*************************************/
142
143 void test7()
144 {
145 cfloat f = 1+0i;
146 f %= 2fi;
147 printf("%f + %fi\n", f.re, f.im);
148 assert(f == 1 + 0i);
149
150 cdouble d = 1+0i;
151 d %= 2i;
152 printf("%f + %fi\n", d.re, d.im);
153 assert(d == 1 + 0i);
154
155 creal r = 1+0i;
156 r %= 2i;
157 printf("%Lf + %Lfi\n", r.re, r.im);
158 assert(r == 1 + 0i);
159 }
160
161 /*************************************/
162
163 void test8()
164 {
165 cfloat f = 1+0i;
166 f %= 2i;
167 printf("%f + %fi\n", f.re, f.im);
168 assert(f == 1);
169
170 cdouble d = 1+0i;
171 d = d % 2i;
172 printf("%f + %fi\n", d.re, d.im);
173 assert(d == 1);
174
175 creal r = 1+0i;
176 r = r % 2i;
177 printf("%Lf + %Lfi\n", r.re, r.im);
178 assert(r == 1);
179 }
180
181 /*************************************/
182
183 class A9
184 {
185 this(int[] params ...)
186 {
187 for (int i = 0; i < params.length; i++)
188 {
189 assert(params[i] == i + 1);
190 }
191 }
192 }
193
194 class B9
195 {
196 this()
197 {
198 init();
199 }
200
201 private void init()
202 {
203 A9 test1 = new A9(1, 2, 3);
204 A9 test2 = new A9(1, 2, 3, 4);
205 int[3] arg;
206 arg[0]=1, arg[1]=2, arg[2]=3;
207 A9 test3 = new A9(arg);
208 }
209 }
210
211 void test9()
212 {
213 B9 test2 = new B9();
214 }
215
216 /*************************************/
217
218 void test10()
219 {
220 auto i = 5u;
221 auto s = typeid(typeof(i)).toString;
222 printf("%.*s\n", s.length, s.ptr);
223 assert(typeid(typeof(i)) == typeid(uint));
224 }
225
226 /*************************************/
227
228 void test11()
229 {
230 printf("%d\n", 3);
231 printf("xhello world!\n");
232 }
233
234 /*************************************/
235
236 void assertEqual(real* a, real* b, string file = __FILE__, size_t line = __LINE__)
237 {
238 auto x = cast(ubyte*)a;
239 auto y = cast(ubyte*)b;
240
241 // Only compare the 10 value bytes, the padding bytes are of undefined
242 // value.
243 version (X86) enum count = 10;
244 else version (X86_64) enum count = 10;
245 else enum count = real.sizeof;
246 for (size_t i = 0; i < count; i++)
247 {
248 if (x[i] != y[i])
249 {
250 printf("%02d: %02x %02x\n", i, x[i], y[i]);
251 import core.exception;
252 throw new AssertError(file, line);
253 }
254 }
255 }
256
257 void assertEqual(creal* a, creal* b, string file = __FILE__, size_t line = __LINE__)
258 {
259 assertEqual(cast(real*)a, cast(real*)b, file, line);
260 assertEqual(cast(real*)a + 1, cast(real*)b + 1, file, line);
261 }
262
263 void test12()
264 {
265 creal a = creal.nan;
266 creal b = real.nan + ireal.nan;
267 assertEqual(&a, &b);
268
269 real c= real.nan;
270 real d=a.re;
271 assertEqual(&c, &d);
272
273 d=a.im;
274 assertEqual(&c, &d);
275 }
276
277 /*************************************/
278
279 void test13()
280 {
281 creal a = creal.infinity;
282 creal b = real.infinity + ireal.infinity;
283 assertEqual(&a, &b);
284
285 real c = real.infinity;
286 real d=a.re;
287 assertEqual(&c, &d);
288
289 d=a.im;
290 assertEqual(&c, &d);
291 }
292
293 /*************************************/
294
295 void test14()
296 {
297 creal a = creal.nan;
298 creal b = creal.nan;
299 b = real.nan + ireal.nan;
300 assertEqual(&a, &b);
301
302 real c = real.nan;
303 real d=a.re;
304 assertEqual(&c, &d);
305
306 d=a.im;
307 assertEqual(&c, &d);
308 }
309
310 /*************************************/
311
312 ireal x15;
313
314 void foo15()
315 {
316 x15 = -x15;
317 }
318
319 void bar15()
320 {
321 return foo15();
322 }
323
324 void test15()
325 {
326 x15=2i;
327 bar15();
328 assert(x15==-2i);
329 }
330
331 /*************************************/
332
333 real x16;
334
335 void foo16()
336 {
337 x16 = -x16;
338 }
339
340 void bar16()
341 {
342 return foo16();
343 }
344
345 void test16()
346 {
347 x16=2;
348 bar16();
349 assert(x16==-2);
350 }
351
352 /*************************************/
353
354 class Bar17
355 {
356 this(...) {}
357 }
358
359 class Foo17
360 {
361 void opAdd (Bar17 b) {}
362 }
363
364 void test17()
365 {
366 auto f = new Foo17;
367 f + new Bar17;
368 }
369
370
371 /*************************************/
372
373 template u18(int n)
374 {
375 static if (n==1) {
376 int a = 1;
377 } else
378 int b = 4;
379 }
380
381 void test18()
382 {
383 mixin u18!(2);
384 assert(b == 4);
385 }
386
387 /*************************************/
388
389 class DP
390 {
391 private:
392 void I(char[] p)
393 {
394 I(p[1..p.length]);
395 }
396 }
397
398 void test19()
399 {
400 }
401
402 /*************************************/
403
404 struct Struct20
405 {
406 int i;
407 }
408
409 void test20()
410 {
411 auto s = new Struct20;
412 s.i = 7;
413 }
414
415 /*************************************/
416
417 class C21(float f)
418 {
419 float ff = f;
420 }
421
422 void test21()
423 {
424 auto a = new C21!(1.2);
425 C21!(1.2) b = new C21!(1.2);
426 }
427
428 /*************************************/
429
430 void test22()
431 {
432 static creal[] params = [1+0i, 3+0i, 5+0i];
433
434 printf("params[0] = %Lf + %Lfi\n", params[0].re, params[0].im);
435 printf("params[1] = %Lf + %Lfi\n", params[1].re, params[1].im);
436 printf("params[2] = %Lf + %Lfi\n", params[2].re, params[2].im);
437
438 creal[] sums = new creal[3];
439 sums[] = 0+0i;
440
441 foreach(creal d; params)
442 {
443 creal prod = d;
444
445 printf("prod = %Lf + %Lfi\n", prod.re, prod.im);
446 for(int i; i<2; i++)
447 {
448 sums[i] += prod;
449 prod *= d;
450 }
451 sums[2] += prod;
452 }
453
454 printf("sums[0] = %Lf + %Lfi", sums[0].re, sums[0].im);
455 assert(sums[0].re==9);
456 assert(sums[0].im==0);
457 assert(sums[1].re==35);
458 assert(sums[1].im==0);
459 assert(sums[2].re==153);
460 assert(sums[2].im==0);
461 }
462
463 /*************************************/
464
465 const int c23 = b23 * b23;
466 const int a23 = 1;
467 const int b23 = a23 * 3;
468
469 template T23(int n)
470 {
471 int[n] x23;
472 }
473
474 mixin T23!(c23);
475
476 void test23()
477 {
478 assert(x23.length==9);
479 }
480
481 /*************************************/
482
483 ifloat func_24_1(ifloat f, double d)
484 {
485 // f /= cast(cdouble)d;
486 return f;
487 }
488
489 ifloat func_24_2(ifloat f, double d)
490 {
491 f = cast(ifloat)(f / cast(cdouble)d);
492 return f;
493 }
494
495 float func_24_3(float f, double d)
496 {
497 // f /= cast(cdouble)d;
498 return f;
499 }
500
501 float func_24_4(float f, double d)
502 {
503 f = cast(float)(f / cast(cdouble)d);
504 return f;
505 }
506
507 void test24()
508 {
509 ifloat f = func_24_1(10i, 8);
510 printf("%fi\n", f);
511 // assert(f == 1.25i);
512
513 f = func_24_2(10i, 8);
514 printf("%fi\n", f);
515 assert(f == 1.25i);
516
517 float g = func_24_3(10, 8);
518 printf("%f\n", g);
519 // assert(g == 1.25);
520
521 g = func_24_4(10, 8);
522 printf("%f\n", g);
523 assert(g == 1.25);
524 }
525
526 /*************************************/
527
528 template cat(int n)
529 {
530 const int dog = n;
531 }
532
533 const char [] bird = "canary";
534
535 const int sheep = cat!(bird.length).dog;
536
537 void test25()
538 {
539 assert(sheep == 6);
540 }
541
542 /*************************************/
543
544 string toString26(cdouble z)
545 {
546 char[ulong.sizeof*8] buf;
547
548 auto len = snprintf(buf.ptr, buf.sizeof, "%f+%fi", z.re, z.im);
549 return buf[0 .. len].idup;
550 }
551
552 void test26()
553 {
554 static cdouble[] A = [1+0i, 0+1i, 1+1i];
555 string s;
556
557 foreach( cdouble z; A )
558 {
559 s = toString26(z);
560 printf("%.*s ", s.length, s.ptr);
561 }
562 printf("\n");
563
564 for(int ii=0; ii<A.length; ii++ )
565 A[ii] += -1i*A[ii];
566
567 assert(A[0] == 1 - 1i);
568 assert(A[1] == 1 + 1i);
569 assert(A[2] == 2);
570
571 foreach( cdouble z; A )
572 {
573 s = toString26(z);
574 printf("%.*s ", s.length, s.ptr);
575 }
576 printf("\n");
577 }
578
579 /*************************************/
580
581 void test27()
582 { int x;
583
584 string s = (int*function(int ...)[]).mangleof;
585 printf("%.*s\n", s.length, s.ptr);
586 assert((int*function(int ...)[]).mangleof == "APFiXPi");
587 assert(typeof(x).mangleof == "i");
588 assert(x.mangleof == "_D6test226test27FZ1xi");
589 }
590
591 /*************************************/
592
593 void test28()
594 {
595 alias cdouble X;
596 X four = cast(X) (4.0i + 0.4);
597 }
598
599 /*************************************/
600
601 void test29()
602 {
603 ulong a = 10_000_000_000_000_000,
604 b = 1_000_000_000_000_000;
605
606 printf("test29\n%lx\n%lx\n%lx\n", a, b, a / b);
607 assert((a / b) == 10);
608 }
609
610 static assert((10_000_000_000_000_000 / 1_000_000_000_000_000) == 10);
611
612 /*************************************/
613
614 template chook(int n)
615 {
616 const int chook = 3;
617 }
618
619 template dog(alias f) {
620 const int dog = chook!(f.mangleof.length);
621 }
622
623 class pig {}
624
625 const int goose = dog!(pig);
626
627 void test30()
628 {
629 printf("%d\n", goose);
630 assert(goose == 3);
631 }
632
633 /*************************************/
634
635 template dog31(string sheep)
636 {
637 immutable string dog31 = "daschund";
638 }
639
640 void test31()
641 {
642 string duck = dog31!("bird"[1..3]);
643
644 assert(duck == "daschund");
645 }
646
647 /*************************************/
648
649 struct particle
650 {
651 int active; /* Active (Yes/No) */
652 float life; /* Particle Life */
653 float fade; /* Fade Speed */
654
655 float r; /* Red Value */
656 float g; /* Green Value */
657 float b; /* Blue Value */
658
659 float x; /* X Position */
660 float y; /* Y Position */
661
662 float xi; /* X Direction */
663 float yi; /* Y Direction */
664
665 float xg; /* X Gravity */
666 float yg; /* Y Gravity */
667 }
668
669 particle particles[10000];
670
671 void test32()
672 {
673 }
674
675 /*************************************/
676
677 class Foo33
678 {
679 template foo()
680 {
681 int foo() { return 6; }
682 }
683 }
684
685
686 void test33()
687 {
688 Foo33 f = new Foo33;
689
690 assert(f.foo!()() == 6);
691 with (f)
692 assert(foo!()() == 6);
693 }
694
695 /*************************************/
696
697 template dog34(string duck)
698 {
699 const int dog34 = 2;
700 }
701
702 void test34()
703 {
704 int aardvark = dog34!("cat" ~ "pig");
705
706 assert(aardvark == 2);
707 }
708
709 /*************************************/
710
711 class A35
712 {
713 private bool quit;
714 void halt() {quit = true;}
715 bool isHalted() {return quit;}
716 }
717
718 void test35()
719 {
720 auto a = new A35;
721
722 a.halt; // error here
723 a.halt();
724
725 a.isHalted; // error here
726 bool done = a.isHalted;
727 if (a.isHalted)
728 {
729 }
730 }
731
732
733 /*************************************/
734
735 void test36()
736 {
737 bool q = (0.9 + 3.5L == 0.9L + 3.5L);
738 assert(q);
739 static assert(0.9 + 3.5L == 0.9L + 3.5L);
740 assert(0.9 + 3.5L == 0.9L + 3.5L);
741 }
742
743 /*************************************/
744
745 abstract class Foo37(T)
746 {
747 void bar () { }
748 }
749
750 class Bar37 : Foo37!(int)
751 {
752 }
753
754 void test37()
755 {
756 auto f = new Bar37;
757 }
758
759 /*************************************/
760
761 void test38()
762 {
763 auto s=`hello`;
764 assert(s.length==5);
765 assert(s[0]=='h');
766 assert(s[1]=='e');
767 assert(s[2]=='l');
768 assert(s[3]=='l');
769 assert(s[4]=='o');
770 }
771
772 /*************************************/
773
774 void test39()
775 {
776 int value=1;
777 string key = "eins";
778 int[char[]] array;
779
780 array[key]=value;
781 int* ptr = key in array;
782
783 assert(value == *ptr);
784 }
785
786 /*************************************/
787
788 void test40()
789 {
790 auto s=r"hello";
791 assert(s.length==5);
792 assert(s[0]=='h');
793 assert(s[1]=='e');
794 assert(s[2]=='l');
795 assert(s[3]=='l');
796 assert(s[4]=='o');
797 }
798
799 /*************************************/
800
801 void test41()
802 {
803 version (Windows)
804 {
805 version(D_InlineAsm){
806 double a = 1.2;
807 double b = 0.2;
808 double c = 1.4;
809
810 asm{
811 movq XMM0, a;
812 movq XMM1, b;
813 addsd XMM1, XMM0;
814 movq c, XMM1;
815 }
816
817 a += b;
818
819 b = a-c;
820 b = (b>0) ? b : (-1 * b);
821
822 assert(b < b.epsilon*4);
823 }
824 }
825 }
826
827 /*************************************/
828
829 const char[] tapir = "some horned animal";
830
831 const byte[] antelope = cast(byte []) tapir;
832
833 void test42()
834 {
835 }
836
837 /*************************************/
838
839 void test43()
840 {
841 string armadillo = "abc" ~ 'a';
842 assert(armadillo == "abca");
843 string armadillo2 = 'b' ~ "abc";
844 assert(armadillo2 == "babc");
845 }
846
847 /*************************************/
848
849 const uint baboon44 = 3;
850
851 const int monkey44 = 4;
852
853 const ape44 = monkey44 * baboon44;
854
855 void test44()
856 {
857 assert(ape44 == 12);
858 }
859
860 /*************************************/
861
862 class A45
863 {
864 this()
865 {
866 b = new B();
867 b.x = 5; // illegal
868 }
869
870 class B
871 {
872 protected int x;
873 }
874
875 B b;
876 }
877
878 void test45()
879 {
880 }
881
882
883 /*************************************/
884
885 class C46(T)
886 {
887 private T i; // or protected or package
888 }
889
890 void test46()
891 {
892 C46!(int) c = new C46!(int); // class t4.C46!(int).C46 member i is not accessible
893 c.i = 10;
894 }
895
896 /*************************************/
897
898 void bug5809()
899 {
900 ushort[2] x = void;
901 x[0] = 0;
902 x[1] = 0x1234;
903 ushort *px = &x[0];
904
905 uint b = px[0];
906
907 assert(px[0] == 0);
908 }
909
910 /*************************************/
911
912 void bug7546()
913 {
914 double p = -0.0;
915 assert(p == 0);
916 }
917
918
919 /*************************************/
920
921 real poly_asm(real x, real[] A)
922 in
923 {
924 assert(A.length > 0);
925 }
926 body
927 {
928 version (D_InlineAsm_X86)
929 {
930 version (linux)
931 {
932 asm // assembler by W. Bright
933 {
934 // EDX = (A.length - 1) * real.sizeof
935 mov ECX,A[EBP] ; // ECX = A.length
936 dec ECX ;
937 lea EDX,[ECX][ECX*8] ;
938 add EDX,ECX ;
939 add EDX,ECX ;
940 add EDX,ECX ;
941 add EDX,A+4[EBP] ;
942 fld real ptr [EDX] ; // ST0 = coeff[ECX]
943 jecxz return_ST ;
944 fld x[EBP] ; // ST0 = x
945 fxch ST(1) ; // ST1 = x, ST0 = r
946 align 4 ;
947 L2: fmul ST,ST(1) ; // r *= x
948 fld real ptr -12[EDX] ;
949 sub EDX,12 ; // deg--
950 faddp ST(1),ST ;
951 dec ECX ;
952 jne L2 ;
953 fxch ST(1) ; // ST1 = r, ST0 = x
954 fstp ST(0) ; // dump x
955 align 4 ;
956 return_ST: ;
957 ;
958 }
959 }
960 else version (OSX)
961 {
962 asm // assembler by W. Bright
963 {
964 // EDX = (A.length - 1) * real.sizeof
965 mov ECX,A[EBP] ; // ECX = A.length
966 dec ECX ;
967 lea EDX,[ECX*8] ;
968 add EDX,EDX ;
969 add EDX,A+4[EBP] ;
970 fld real ptr [EDX] ; // ST0 = coeff[ECX]
971 jecxz return_ST ;
972 fld x[EBP] ; // ST0 = x
973 fxch ST(1) ; // ST1 = x, ST0 = r
974 align 4 ;
975 L2: fmul ST,ST(1) ; // r *= x
976 fld real ptr -16[EDX] ;
977 sub EDX,16 ; // deg--
978 faddp ST(1),ST ;
979 dec ECX ;
980 jne L2 ;
981 fxch ST(1) ; // ST1 = r, ST0 = x
982 fstp ST(0) ; // dump x
983 align 4 ;
984 return_ST: ;
985 ;
986 }
987 }
988 else version (FreeBSD)
989 {
990 asm // assembler by W. Bright
991 {
992 // EDX = (A.length - 1) * real.sizeof
993 mov ECX,A[EBP] ; // ECX = A.length
994 dec ECX ;
995 lea EDX,[ECX][ECX*8] ;
996 add EDX,ECX ;
997 add EDX,ECX ;
998 add EDX,ECX ;
999 add EDX,A+4[EBP] ;
1000 fld real ptr [EDX] ; // ST0 = coeff[ECX]
1001 jecxz return_ST ;
1002 fld x[EBP] ; // ST0 = x
1003 fxch ST(1) ; // ST1 = x, ST0 = r
1004 align 4 ;
1005 L2: fmul ST,ST(1) ; // r *= x
1006 fld real ptr -12[EDX] ;
1007 sub EDX,12 ; // deg--
1008 faddp ST(1),ST ;
1009 dec ECX ;
1010 jne L2 ;
1011 fxch ST(1) ; // ST1 = r, ST0 = x
1012 fstp ST(0) ; // dump x
1013 align 4 ;
1014 return_ST: ;
1015 ;
1016 }
1017 }
1018 else version (Solaris)
1019 {
1020 asm // assembler by W. Bright
1021 {
1022 // EDX = (A.length - 1) * real.sizeof
1023 mov ECX,A[EBP] ; // ECX = A.length
1024 dec ECX ;
1025 lea EDX,[ECX][ECX*8] ;
1026 add EDX,ECX ;
1027 add EDX,ECX ;
1028 add EDX,ECX ;
1029 add EDX,A+4[EBP] ;
1030 fld real ptr [EDX] ; // ST0 = coeff[ECX]
1031 jecxz return_ST ;
1032 fld x[EBP] ; // ST0 = x
1033 fxch ST(1) ; // ST1 = x, ST0 = r
1034 align 4 ;
1035 L2: fmul ST,ST(1) ; // r *= x
1036 fld real ptr -12[EDX] ;
1037 sub EDX,12 ; // deg--
1038 faddp ST(1),ST ;
1039 dec ECX ;
1040 jne L2 ;
1041 fxch ST(1) ; // ST1 = r, ST0 = x
1042 fstp ST(0) ; // dump x
1043 align 4 ;
1044 return_ST: ;
1045 ;
1046 }
1047 }
1048 else
1049 {
1050 asm // assembler by W. Bright
1051 {
1052 // EDX = (A.length - 1) * real.sizeof
1053 mov ECX,A[EBP] ; // ECX = A.length
1054 dec ECX ;
1055 lea EDX,[ECX][ECX*8] ;
1056 add EDX,ECX ;
1057 add EDX,A+4[EBP] ;
1058 fld real ptr [EDX] ; // ST0 = coeff[ECX]
1059 jecxz return_ST ;
1060 fld x[EBP] ; // ST0 = x
1061 fxch ST(1) ; // ST1 = x, ST0 = r
1062 align 4 ;
1063 L2: fmul ST,ST(1) ; // r *= x
1064 fld real ptr -10[EDX] ;
1065 sub EDX,10 ; // deg--
1066 faddp ST(1),ST ;
1067 dec ECX ;
1068 jne L2 ;
1069 fxch ST(1) ; // ST1 = r, ST0 = x
1070 fstp ST(0) ; // dump x
1071 align 4 ;
1072 return_ST: ;
1073 ;
1074 }
1075 }
1076 }
1077 else
1078 {
1079 printf("Sorry, you don't seem to have InlineAsm_X86\n");
1080 return 0;
1081 }
1082 }
1083
1084 real poly_c(real x, real[] A)
1085 in
1086 {
1087 assert(A.length > 0);
1088 }
1089 body
1090 {
1091 ptrdiff_t i = A.length - 1;
1092 real r = A[i];
1093 while (--i >= 0)
1094 {
1095 r *= x;
1096 r += A[i];
1097 }
1098 return r;
1099 }
1100
1101 void test47()
1102 {
1103 real x = 3.1;
1104 static real pp[] = [56.1, 32.7, 6];
1105 real r;
1106
1107 printf("The result should be %Lf\n",(56.1L + (32.7L + 6L * x) * x));
1108 printf("The C version outputs %Lf\n", poly_c(x, pp));
1109 printf("The asm version outputs %Lf\n", poly_asm(x, pp));
1110 printf("The std.math version outputs %Lf\n", poly(x, pp));
1111
1112 r = (56.1L + (32.7L + 6L * x) * x);
1113 assert(r == poly_c(x, pp));
1114 version (D_InlineAsm_X86)
1115 assert(r == poly_asm(x, pp));
1116 assert(r == poly(x, pp));
1117 }
1118
1119 /*************************************/
1120
1121 const c48 = 1uL-1;
1122
1123 void test48()
1124 {
1125 assert(c48 == 0);
1126 }
1127
1128 /*************************************/
1129
1130 template cat49()
1131 {
1132 static assert(1); // OK
1133 static if (1)
1134 {
1135 static assert(1); // doesn't work
1136 static if (1)
1137 {
1138 static assert(1); // OK
1139 const int cat49 = 3;
1140 }
1141 }
1142 }
1143
1144 void test49()
1145 {
1146 const int a = cat49!();
1147 assert(a == 3);
1148 }
1149
1150 /*************************************/
1151
1152 void test50()
1153 {
1154 if (auto x = 1)
1155 {
1156 assert(typeid(typeof(x)) == typeid(int));
1157 assert(x == 1);
1158 }
1159 else
1160 assert(0);
1161
1162 if (int x = 1)
1163 {
1164 assert(typeid(typeof(x)) == typeid(int));
1165 assert(x == 1);
1166 }
1167 else
1168 assert(0);
1169
1170 if (1)
1171 {
1172 }
1173 else
1174 assert(0);
1175 }
1176
1177 /*************************************/
1178
1179 void test51()
1180 {
1181 bool b;
1182 assert(b == false);
1183 b &= 1;
1184 assert(b == false);
1185 b |= 1;
1186 assert(b == true);
1187 b ^= 1;
1188 assert(b == false);
1189 b = b | true;
1190 assert(b == true);
1191 b = b & false;
1192 assert(b == false);
1193 b = b ^ true;
1194 assert(b == true);
1195 b = !b;
1196 assert(b == false);
1197 }
1198
1199 /*************************************/
1200
1201 alias int function (int) x52;
1202
1203 template T52(string str){
1204 const int T52 = 1;
1205 }
1206
1207 static assert(T52!(x52.mangleof));
1208
1209 void test52()
1210 {
1211 }
1212
1213 /*************************************/
1214 import std.stdio;
1215 import core.stdc.stdarg;
1216
1217 void myfunc(int a1, ...) {
1218 va_list argument_list;
1219 TypeInfo argument_type;
1220 string sa; int ia; double da;
1221 writefln("%d variable arguments", _arguments.length);
1222 writefln("argument types %s", _arguments);
1223 va_start(argument_list, a1);
1224 for (int i = 0; i < _arguments.length; ) {
1225 if ((argument_type=_arguments[i++]) == typeid(string)) {
1226 va_arg(argument_list, sa);
1227 writefln("%d) string arg = '%s', length %d", i+1, sa.length<=20? sa : "?", sa.length);
1228 } else if (argument_type == typeid(int)) {
1229 va_arg(argument_list, ia);
1230 writefln("%d) int arg = %d", i+1, ia);
1231 } else if (argument_type == typeid(double)) {
1232 va_arg(argument_list, da);
1233 writefln("%d) double arg = %f", i+1, da);
1234 } else {
1235 throw new Exception("invalid argument type");
1236 }
1237 }
1238 va_end(argument_list);
1239 }
1240
1241 void test6758() {
1242 myfunc(1, 2, 3, 4, 5, 6, 7, 8, "9", "10"); // Fails.
1243 myfunc(1, 2.0, 3, 4, 5, 6, 7, 8, "9", "10"); // Works OK.
1244 myfunc(1, 2, 3, 4, 5, 6, 7, "8", "9", "10"); // Works OK.
1245 myfunc(1, "2", 3, 4, 5, 6, 7, 8, "9", "10"); // Works OK.
1246 }
1247
1248
1249 /*************************************/
1250
1251 int main()
1252 {
1253 test1();
1254 test2();
1255 test3();
1256 test4();
1257 test5();
1258 test6();
1259 test7();
1260 test8();
1261 test9();
1262 test10();
1263 test11();
1264 test12();
1265 test13();
1266 test14();
1267 test15();
1268 test16();
1269 test17();
1270 test18();
1271 test19();
1272 test20();
1273 test21();
1274 test22();
1275 test23();
1276 test24();
1277 test25();
1278 test26();
1279 test27();
1280 test28();
1281 test29();
1282 test30();
1283 test31();
1284 test32();
1285 test33();
1286 test34();
1287 test35();
1288 test36();
1289 test37();
1290 test38();
1291 test39();
1292 test40();
1293 test41();
1294 test42();
1295 test43();
1296 test44();
1297 test45();
1298 test46();
1299 bug5809();
1300 bug7546();
1301 test47();
1302 test48();
1303 test49();
1304 test50();
1305 test51();
1306 test52();
1307 test6758();
1308
1309 printf("Success\n");
1310 return 0;
1311 }