1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
|
#define GLM_FORCE_EXPLICIT_CTOR
#include <glm/gtc/constants.hpp>
#include <glm/gtc/random.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/ext/scalar_relational.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/ext/vector_float1.hpp>
#include <glm/common.hpp>
#include <glm/vec4.hpp>
#include <glm/vec3.hpp>
#include <glm/vec2.hpp>
#include <vector>
#include <cstdio>
#include <cmath>
#include <ctime>
// This file has divisions by zero to test isnan
#if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(disable : 4723)
#endif
namespace floor_
{
static int test()
{
int Error = 0;
{
float A = 1.1f;
float B = glm::floor(A);
Error += glm::equal(B, 1.f, 0.0001f) ? 0 : 1;
}
{
double A = 1.1;
double B = glm::floor(A);
Error += glm::equal(B, 1.0, 0.0001) ? 0 : 1;
}
{
glm::vec1 A(1.1f);
glm::vec1 B = glm::floor(A);
Error += glm::all(glm::equal(B, glm::vec1(1.0), 0.0001f)) ? 0 : 1;
}
{
glm::dvec1 A(1.1);
glm::dvec1 B = glm::floor(A);
Error += glm::all(glm::equal(B, glm::dvec1(1.0), 0.0001)) ? 0 : 1;
}
{
glm::vec2 A(1.1f);
glm::vec2 B = glm::floor(A);
Error += glm::all(glm::equal(B, glm::vec2(1.0), 0.0001f)) ? 0 : 1;
}
{
glm::dvec2 A(1.1);
glm::dvec2 B = glm::floor(A);
Error += glm::all(glm::equal(B, glm::dvec2(1.0), 0.0001)) ? 0 : 1;
}
{
glm::vec3 A(1.1f);
glm::vec3 B = glm::floor(A);
Error += glm::all(glm::equal(B, glm::vec3(1.0), 0.0001f)) ? 0 : 1;
}
{
glm::dvec3 A(1.1);
glm::dvec3 B = glm::floor(A);
Error += glm::all(glm::equal(B, glm::dvec3(1.0), 0.0001)) ? 0 : 1;
}
{
glm::vec4 A(1.1f);
glm::vec4 B = glm::floor(A);
Error += glm::all(glm::equal(B, glm::vec4(1.0), 0.0001f)) ? 0 : 1;
}
{
glm::dvec4 A(1.1);
glm::dvec4 B = glm::floor(A);
Error += glm::all(glm::equal(B, glm::dvec4(1.0), 0.0001)) ? 0 : 1;
}
return Error;
}
}//namespace floor
namespace modf_
{
static int test()
{
int Error(0);
{
float X(1.5f);
float I(0.0f);
float A = glm::modf(X, I);
Error += glm::equal(I, 1.0f, 0.0001f) ? 0 : 1;
Error += glm::equal(A, 0.5f, 0.0001f) ? 0 : 1;
}
{
glm::vec4 X(1.1f, 1.2f, 1.5f, 1.7f);
glm::vec4 I(0.0f);
glm::vec4 A = glm::modf(X, I);
Error += glm::ivec4(I) == glm::ivec4(1) ? 0 : 1;
Error += glm::all(glm::equal(A, glm::vec4(0.1f, 0.2f, 0.5f, 0.7f), 0.00001f)) ? 0 : 1;
}
{
glm::dvec4 X(1.1, 1.2, 1.5, 1.7);
glm::dvec4 I(0.0);
glm::dvec4 A = glm::modf(X, I);
Error += glm::ivec4(I) == glm::ivec4(1) ? 0 : 1;
Error += glm::all(glm::equal(A, glm::dvec4(0.1, 0.2, 0.5, 0.7), 0.000000001)) ? 0 : 1;
}
{
double X(1.5);
double I(0.0);
double A = glm::modf(X, I);
Error += glm::equal(I, 1.0, 0.0001) ? 0 : 1;
Error += glm::equal(A, 0.5, 0.0001) ? 0 : 1;
}
return Error;
}
}//namespace modf
namespace mod_
{
static int test()
{
int Error(0);
{
float A(1.5f);
float B(1.0f);
float C = glm::mod(A, B);
Error += glm::equal(C, 0.5f, 0.00001f) ? 0 : 1;
}
{
float A(-0.2f);
float B(1.0f);
float C = glm::mod(A, B);
Error += glm::equal(C, 0.8f, 0.00001f) ? 0 : 1;
}
{
float A(3.0);
float B(2.0f);
float C = glm::mod(A, B);
Error += glm::equal(C, 1.0f, 0.00001f) ? 0 : 1;
}
{
glm::vec4 A(3.0);
float B(2.0f);
glm::vec4 C = glm::mod(A, B);
Error += glm::all(glm::equal(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
}
{
glm::vec4 A(3.0);
glm::vec4 B(2.0f);
glm::vec4 C = glm::mod(A, B);
Error += glm::all(glm::equal(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace mod_
namespace floatBitsToInt
{
static int test()
{
int Error = 0;
{
float A = 1.0f;
int B = glm::floatBitsToInt(A);
float C = glm::intBitsToFloat(B);
Error += glm::equal(A, C, 0.0001f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::ivec2 B = glm::floatBitsToInt(A);
glm::vec2 C = glm::intBitsToFloat(B);
Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::ivec3 B = glm::floatBitsToInt(A);
glm::vec3 C = glm::intBitsToFloat(B);
Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::ivec4 B = glm::floatBitsToInt(A);
glm::vec4 C = glm::intBitsToFloat(B);
Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1;
}
return Error;
}
}//namespace floatBitsToInt
namespace floatBitsToUint
{
static int test()
{
int Error = 0;
{
float A = 1.0f;
glm::uint B = glm::floatBitsToUint(A);
float C = glm::uintBitsToFloat(B);
Error += glm::equal(A, C, 0.0001f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::uvec2 B = glm::floatBitsToUint(A);
glm::vec2 C = glm::uintBitsToFloat(B);
Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::uvec3 B = glm::floatBitsToUint(A);
glm::vec3 C = glm::uintBitsToFloat(B);
Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::uvec4 B = glm::floatBitsToUint(A);
glm::vec4 C = glm::uintBitsToFloat(B);
Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1;
}
return Error;
}
}//namespace floatBitsToUint
namespace min_
{
static int test()
{
int Error = 0;
glm::vec1 A0 = glm::min(glm::vec1(1), glm::vec1(1));
bool A1 = glm::all(glm::equal(A0, glm::vec1(1), glm::epsilon<float>()));
Error += A1 ? 0 : 1;
glm::vec2 B0 = glm::min(glm::vec2(1), glm::vec2(1));
glm::vec2 B1 = glm::min(glm::vec2(1), 1.0f);
bool B2 = glm::all(glm::equal(B0, B1, glm::epsilon<float>()));
Error += B2 ? 0 : 1;
glm::vec3 C0 = glm::min(glm::vec3(1), glm::vec3(1));
glm::vec3 C1 = glm::min(glm::vec3(1), 1.0f);
bool C2 = glm::all(glm::equal(C0, C1, glm::epsilon<float>()));
Error += C2 ? 0 : 1;
glm::vec4 D0 = glm::min(glm::vec4(1), glm::vec4(1));
glm::vec4 D1 = glm::min(glm::vec4(1), 1.0f);
bool D2 = glm::all(glm::equal(D0, D1, glm::epsilon<float>()));
Error += D2 ? 0 : 1;
return Error;
}
int min_tern(int a, int b)
{
return a < b ? a : b;
}
int min_int(int x, int y)
{
return y ^ ((x ^ y) & -(x < y));
}
static int perf(std::size_t Count)
{
std::vector<int> A(Count);
std::vector<int> B(Count);
std::size_t const InternalCount = 200000;
for(std::size_t i = 0; i < Count; ++i)
{
A[i] = glm::linearRand(-1000, 1000);
B[i] = glm::linearRand(-1000, 1000);
}
int Error = 0;
glm::int32 SumA = 0;
{
std::clock_t Timestamp0 = std::clock();
for (std::size_t j = 0; j < InternalCount; ++j)
for (std::size_t i = 0; i < Count; ++i)
SumA += min_tern(A[i], B[i]);
std::clock_t Timestamp1 = std::clock();
std::printf("min_tern Time %d clocks\n", static_cast<int>(Timestamp1 - Timestamp0));
}
glm::int32 SumB = 0;
{
std::clock_t Timestamp0 = std::clock();
for (std::size_t j = 0; j < InternalCount; ++j)
for (std::size_t i = 0; i < Count; ++i)
SumB += min_int(A[i], B[i]);
std::clock_t Timestamp1 = std::clock();
std::printf("min_int Time %d clocks\n", static_cast<int>(Timestamp1 - Timestamp0));
}
Error += SumA == SumB ? 0 : 1;
return Error;
}
}//namespace min_
namespace max_
{
static int test()
{
int Error = 0;
glm::vec1 A0 = glm::max(glm::vec1(1), glm::vec1(1));
bool A1 = glm::all(glm::equal(A0, glm::vec1(1), glm::epsilon<float>()));
Error += A1 ? 0 : 1;
glm::vec2 B0 = glm::max(glm::vec2(1), glm::vec2(1));
glm::vec2 B1 = glm::max(glm::vec2(1), 1.0f);
bool B2 = glm::all(glm::equal(B0, B1, glm::epsilon<float>()));
Error += B2 ? 0 : 1;
glm::vec3 C0 = glm::max(glm::vec3(1), glm::vec3(1));
glm::vec3 C1 = glm::max(glm::vec3(1), 1.0f);
bool C2 = glm::all(glm::equal(C0, C1, glm::epsilon<float>()));
Error += C2 ? 0 : 1;
glm::vec4 D0 = glm::max(glm::vec4(1), glm::vec4(1));
glm::vec4 D1 = glm::max(glm::vec4(1), 1.0f);
bool D2 = glm::all(glm::equal(D0, D1, glm::epsilon<float>()));
Error += D2 ? 0 : 1;
return Error;
}
}//namespace max_
namespace clamp_
{
static int test()
{
int Error = 0;
return Error;
}
}//namespace clamp_
namespace mix_
{
template<typename T, typename B>
struct entry
{
T x;
T y;
B a;
T Result;
};
entry<float, bool> const TestBool[] =
{
{0.0f, 1.0f, false, 0.0f},
{0.0f, 1.0f, true, 1.0f},
{-1.0f, 1.0f, false, -1.0f},
{-1.0f, 1.0f, true, 1.0f}
};
entry<float, float> const TestFloat[] =
{
{0.0f, 1.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 1.0f, 1.0f},
{-1.0f, 1.0f, 0.0f, -1.0f},
{-1.0f, 1.0f, 1.0f, 1.0f}
};
entry<glm::vec2, bool> const TestVec2Bool[] =
{
{glm::vec2(0.0f), glm::vec2(1.0f), false, glm::vec2(0.0f)},
{glm::vec2(0.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)},
{glm::vec2(-1.0f), glm::vec2(1.0f), false, glm::vec2(-1.0f)},
{glm::vec2(-1.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)}
};
entry<glm::vec2, glm::bvec2> const TestBVec2[] =
{
{glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(0.0f)},
{glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
{glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(-1.0f)},
{glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
{glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true, false), glm::vec2(1.0f, -1.0f)}
};
entry<glm::vec3, bool> const TestVec3Bool[] =
{
{glm::vec3(0.0f), glm::vec3(1.0f), false, glm::vec3(0.0f)},
{glm::vec3(0.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)},
{glm::vec3(-1.0f), glm::vec3(1.0f), false, glm::vec3(-1.0f)},
{glm::vec3(-1.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)}
};
entry<glm::vec3, glm::bvec3> const TestBVec3[] =
{
{glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(0.0f)},
{glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
{glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(-1.0f)},
{glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
{glm::vec3(1.0f, 2.0f, 3.0f), glm::vec3(4.0f, 5.0f, 6.0f), glm::bvec3(true, false, true), glm::vec3(4.0f, 2.0f, 6.0f)}
};
entry<glm::vec4, bool> const TestVec4Bool[] =
{
{glm::vec4(0.0f), glm::vec4(1.0f), false, glm::vec4(0.0f)},
{glm::vec4(0.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)},
{glm::vec4(-1.0f), glm::vec4(1.0f), false, glm::vec4(-1.0f)},
{glm::vec4(-1.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)}
};
entry<glm::vec4, glm::bvec4> const TestBVec4[] =
{
{glm::vec4(0.0f, 0.0f, 1.0f, 1.0f), glm::vec4(2.0f, 2.0f, 3.0f, 3.0f), glm::bvec4(false, true, false, true), glm::vec4(0.0f, 2.0f, 1.0f, 3.0f)},
{glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
{glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(-1.0f)},
{glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
{glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(5.0f, 6.0f, 7.0f, 8.0f), glm::bvec4(true, false, true, false), glm::vec4(5.0f, 2.0f, 7.0f, 4.0f)}
};
static int test()
{
int Error = 0;
// Float with bool
{
for(std::size_t i = 0; i < sizeof(TestBool) / sizeof(entry<float, bool>); ++i)
{
float Result = glm::mix(TestBool[i].x, TestBool[i].y, TestBool[i].a);
Error += glm::equal(Result, TestBool[i].Result, glm::epsilon<float>()) ? 0 : 1;
}
}
// Float with float
{
for(std::size_t i = 0; i < sizeof(TestFloat) / sizeof(entry<float, float>); ++i)
{
float Result = glm::mix(TestFloat[i].x, TestFloat[i].y, TestFloat[i].a);
Error += glm::equal(Result, TestFloat[i].Result, glm::epsilon<float>()) ? 0 : 1;
}
}
// vec2 with bool
{
for(std::size_t i = 0; i < sizeof(TestVec2Bool) / sizeof(entry<glm::vec2, bool>); ++i)
{
glm::vec2 Result = glm::mix(TestVec2Bool[i].x, TestVec2Bool[i].y, TestVec2Bool[i].a);
Error += glm::equal(Result.x, TestVec2Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.y, TestVec2Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
}
}
// vec2 with bvec2
{
for(std::size_t i = 0; i < sizeof(TestBVec2) / sizeof(entry<glm::vec2, glm::bvec2>); ++i)
{
glm::vec2 Result = glm::mix(TestBVec2[i].x, TestBVec2[i].y, TestBVec2[i].a);
Error += glm::equal(Result.x, TestBVec2[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.y, TestBVec2[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
}
}
// vec3 with bool
{
for(std::size_t i = 0; i < sizeof(TestVec3Bool) / sizeof(entry<glm::vec3, bool>); ++i)
{
glm::vec3 Result = glm::mix(TestVec3Bool[i].x, TestVec3Bool[i].y, TestVec3Bool[i].a);
Error += glm::equal(Result.x, TestVec3Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.y, TestVec3Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.z, TestVec3Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
}
}
// vec3 with bvec3
{
for(std::size_t i = 0; i < sizeof(TestBVec3) / sizeof(entry<glm::vec3, glm::bvec3>); ++i)
{
glm::vec3 Result = glm::mix(TestBVec3[i].x, TestBVec3[i].y, TestBVec3[i].a);
Error += glm::equal(Result.x, TestBVec3[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.y, TestBVec3[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.z, TestBVec3[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
}
}
// vec4 with bool
{
for(std::size_t i = 0; i < sizeof(TestVec4Bool) / sizeof(entry<glm::vec4, bool>); ++i)
{
glm::vec4 Result = glm::mix(TestVec4Bool[i].x, TestVec4Bool[i].y, TestVec4Bool[i].a);
Error += glm::equal(Result.x, TestVec4Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.y, TestVec4Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.z, TestVec4Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.w, TestVec4Bool[i].Result.w, glm::epsilon<float>()) ? 0 : 1;
}
}
// vec4 with bvec4
{
for(std::size_t i = 0; i < sizeof(TestBVec4) / sizeof(entry<glm::vec4, glm::bvec4>); ++i)
{
glm::vec4 Result = glm::mix(TestBVec4[i].x, TestBVec4[i].y, TestBVec4[i].a);
Error += glm::equal(Result.x, TestBVec4[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.y, TestBVec4[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.z, TestBVec4[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(Result.w, TestBVec4[i].Result.w, glm::epsilon<float>()) ? 0 : 1;
}
}
return Error;
}
}//namespace mix_
namespace step_
{
template<typename EDGE, typename VEC>
struct entry
{
EDGE edge;
VEC x;
VEC result;
};
entry<float, glm::vec4> TestVec4Scalar [] =
{
{ 1.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
{ 0.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
{ 0.0f, glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(0.0f) }
};
entry<glm::vec4, glm::vec4> TestVec4Vector [] =
{
{ glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(-2.0f, -3.0f, -4.0f, -5.0f), glm::vec4(0.0f) },
{ glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
{ glm::vec4( 2.0f, 3.0f, 4.0f, 5.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(0.0f) },
{ glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4(-1.0f,-2.0f,-3.0f,-4.0f), glm::vec4(0.0f) }
};
static int test()
{
int Error = 0;
// scalar
{
float const Edge = 2.0f;
float const A = glm::step(Edge, 1.0f);
Error += glm::equal(A, 0.0f, glm::epsilon<float>()) ? 0 : 1;
float const B = glm::step(Edge, 3.0f);
Error += glm::equal(B, 1.0f, glm::epsilon<float>()) ? 0 : 1;
float const C = glm::step(Edge, 2.0f);
Error += glm::equal(C, 1.0f, glm::epsilon<float>()) ? 0 : 1;
}
// vec4 and float
{
for (std::size_t i = 0; i < sizeof(TestVec4Scalar) / sizeof(entry<float, glm::vec4>); ++i)
{
glm::vec4 Result = glm::step(TestVec4Scalar[i].edge, TestVec4Scalar[i].x);
Error += glm::all(glm::equal(Result, TestVec4Scalar[i].result, glm::epsilon<float>())) ? 0 : 1;
}
}
// vec4 and vec4
{
for (std::size_t i = 0; i < sizeof(TestVec4Vector) / sizeof(entry<glm::vec4, glm::vec4>); ++i)
{
glm::vec4 Result = glm::step(TestVec4Vector[i].edge, TestVec4Vector[i].x);
Error += glm::all(glm::equal(Result, TestVec4Vector[i].result, glm::epsilon<float>())) ? 0 : 1;
}
}
return Error;
}
}//namespace step_
namespace round_
{
static int test()
{
int Error = 0;
{
float A = glm::round(0.0f);
Error += glm::equal(A, 0.0f, glm::epsilon<float>()) ? 0 : 1;
float B = glm::round(0.5f);
Error += glm::equal(B, 1.0f, glm::epsilon<float>()) ? 0 : 1;
float C = glm::round(1.0f);
Error += glm::equal(C, 1.0f, glm::epsilon<float>()) ? 0 : 1;
float D = glm::round(0.1f);
Error += glm::equal(D, 0.0f, glm::epsilon<float>()) ? 0 : 1;
float E = glm::round(0.9f);
Error += glm::equal(E, 1.0f, glm::epsilon<float>()) ? 0 : 1;
float F = glm::round(1.5f);
Error += glm::equal(F, 2.0f, glm::epsilon<float>()) ? 0 : 1;
float G = glm::round(1.9f);
Error += glm::equal(G, 2.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
float A = glm::round(-0.0f);
Error += glm::equal(A, 0.0f, glm::epsilon<float>()) ? 0 : 1;
float B = glm::round(-0.5f);
Error += glm::equal(B, -1.0f, glm::epsilon<float>()) ? 0 : 1;
float C = glm::round(-1.0f);
Error += glm::equal(C, -1.0f, glm::epsilon<float>()) ? 0 : 1;
float D = glm::round(-0.1f);
Error += glm::equal(D, 0.0f, glm::epsilon<float>()) ? 0 : 1;
float E = glm::round(-0.9f);
Error += glm::equal(E, -1.0f, glm::epsilon<float>()) ? 0 : 1;
float F = glm::round(-1.5f);
Error += glm::equal(F, -2.0f, glm::epsilon<float>()) ? 0 : 1;
float G = glm::round(-1.9f);
Error += glm::equal(G, -2.0f, glm::epsilon<float>()) ? 0 : 1;
}
return Error;
}
}//namespace round_
namespace roundEven
{
static int test()
{
int Error = 0;
{
float A1 = glm::roundEven(-1.5f);
Error += glm::equal(A1, -2.0f, 0.0001f) ? 0 : 1;
float A2 = glm::roundEven(1.5f);
Error += glm::equal(A2, 2.0f, 0.0001f) ? 0 : 1;
float A5 = glm::roundEven(-2.5f);
Error += glm::equal(A5, -2.0f, 0.0001f) ? 0 : 1;
float A6 = glm::roundEven(2.5f);
Error += glm::equal(A6, 2.0f, 0.0001f) ? 0 : 1;
float A3 = glm::roundEven(-3.5f);
Error += glm::equal(A3, -4.0f, 0.0001f) ? 0 : 1;
float A4 = glm::roundEven(3.5f);
Error += glm::equal(A4, 4.0f, 0.0001f) ? 0 : 1;
float C7 = glm::roundEven(-4.5f);
Error += glm::equal(C7, -4.0f, 0.0001f) ? 0 : 1;
float C8 = glm::roundEven(4.5f);
Error += glm::equal(C8, 4.0f, 0.0001f) ? 0 : 1;
float C1 = glm::roundEven(-5.5f);
Error += glm::equal(C1, -6.0f, 0.0001f) ? 0 : 1;
float C2 = glm::roundEven(5.5f);
Error += glm::equal(C2, 6.0f, 0.0001f) ? 0 : 1;
float C3 = glm::roundEven(-6.5f);
Error += glm::equal(C3, -6.0f, 0.0001f) ? 0 : 1;
float C4 = glm::roundEven(6.5f);
Error += glm::equal(C4, 6.0f, 0.0001f) ? 0 : 1;
float C5 = glm::roundEven(-7.5f);
Error += glm::equal(C5, -8.0f, 0.0001f) ? 0 : 1;
float C6 = glm::roundEven(7.5f);
Error += glm::equal(C6, 8.0f, 0.0001f) ? 0 : 1;
Error += 0;
}
{
float A7 = glm::roundEven(-2.4f);
Error += glm::equal(A7, -2.0f, 0.0001f) ? 0 : 1;
float A8 = glm::roundEven(2.4f);
Error += glm::equal(A8, 2.0f, 0.0001f) ? 0 : 1;
float B1 = glm::roundEven(-2.6f);
Error += glm::equal(B1, -3.0f, 0.0001f) ? 0 : 1;
float B2 = glm::roundEven(2.6f);
Error += glm::equal(B2, 3.0f, 0.0001f) ? 0 : 1;
float B3 = glm::roundEven(-2.0f);
Error += glm::equal(B3, -2.0f, 0.0001f) ? 0 : 1;
float B4 = glm::roundEven(2.0f);
Error += glm::equal(B4, 2.0f, 0.0001f) ? 0 : 1;
Error += 0;
}
{
float A = glm::roundEven(0.0f);
Error += glm::equal(A, 0.0f, glm::epsilon<float>()) ? 0 : 1;
float B = glm::roundEven(0.5f);
Error += glm::equal(B, 0.0f, glm::epsilon<float>()) ? 0 : 1;
float C = glm::roundEven(1.0f);
Error += glm::equal(C, 1.0f, glm::epsilon<float>()) ? 0 : 1;
float D = glm::roundEven(0.1f);
Error += glm::equal(D, 0.0f, glm::epsilon<float>()) ? 0 : 1;
float E = glm::roundEven(0.9f);
Error += glm::equal(E, 1.0f, glm::epsilon<float>()) ? 0 : 1;
float F = glm::roundEven(1.5f);
Error += glm::equal(F, 2.0f, glm::epsilon<float>()) ? 0 : 1;
float G = glm::roundEven(1.9f);
Error += glm::equal(G, 2.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
float A = glm::roundEven(-0.0f);
Error += glm::equal(A, 0.0f, glm::epsilon<float>()) ? 0 : 1;
float B = glm::roundEven(-0.5f);
Error += glm::equal(B, -0.0f, glm::epsilon<float>()) ? 0 : 1;
float C = glm::roundEven(-1.0f);
Error += glm::equal(C, -1.0f, glm::epsilon<float>()) ? 0 : 1;
float D = glm::roundEven(-0.1f);
Error += glm::equal(D, 0.0f, glm::epsilon<float>()) ? 0 : 1;
float E = glm::roundEven(-0.9f);
Error += glm::equal(E, -1.0f, glm::epsilon<float>()) ? 0 : 1;
float F = glm::roundEven(-1.5f);
Error += glm::equal(F, -2.0f, glm::epsilon<float>()) ? 0 : 1;
float G = glm::roundEven(-1.9f);
Error += glm::equal(G, -2.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
float A = glm::roundEven(1.5f);
Error += glm::equal(A, 2.0f, glm::epsilon<float>()) ? 0 : 1;
float B = glm::roundEven(2.5f);
Error += glm::equal(B, 2.0f, glm::epsilon<float>()) ? 0 : 1;
float C = glm::roundEven(3.5f);
Error += glm::equal(C, 4.0f, glm::epsilon<float>()) ? 0 : 1;
float D = glm::roundEven(4.5f);
Error += glm::equal(D, 4.0f, glm::epsilon<float>()) ? 0 : 1;
float E = glm::roundEven(5.5f);
Error += glm::equal(E, 6.0f, glm::epsilon<float>()) ? 0 : 1;
float F = glm::roundEven(6.5f);
Error += glm::equal(F, 6.0f, glm::epsilon<float>()) ? 0 : 1;
float G = glm::roundEven(7.5f);
Error += glm::equal(G, 8.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
float A = glm::roundEven(-1.5f);
Error += glm::equal(A, -2.0f, glm::epsilon<float>()) ? 0 : 1;
float B = glm::roundEven(-2.5f);
Error += glm::equal(B, -2.0f, glm::epsilon<float>()) ? 0 : 1;
float C = glm::roundEven(-3.5f);
Error += glm::equal(C, -4.0f, glm::epsilon<float>()) ? 0 : 1;
float D = glm::roundEven(-4.5f);
Error += glm::equal(D, -4.0f, glm::epsilon<float>()) ? 0 : 1;
float E = glm::roundEven(-5.5f);
Error += glm::equal(E, -6.0f, glm::epsilon<float>()) ? 0 : 1;
float F = glm::roundEven(-6.5f);
Error += glm::equal(F, -6.0f, glm::epsilon<float>()) ? 0 : 1;
float G = glm::roundEven(-7.5f);
Error += glm::equal(G, -8.0f, glm::epsilon<float>()) ? 0 : 1;
}
return Error;
}
}//namespace roundEven
namespace isnan_
{
static int test()
{
int Error = 0;
float Zero_f = 0.0;
double Zero_d = 0.0;
{
Error += true == glm::isnan(0.0/Zero_d) ? 0 : 1;
Error += true == glm::any(glm::isnan(glm::dvec2(0.0 / Zero_d))) ? 0 : 1;
Error += true == glm::any(glm::isnan(glm::dvec3(0.0 / Zero_d))) ? 0 : 1;
Error += true == glm::any(glm::isnan(glm::dvec4(0.0 / Zero_d))) ? 0 : 1;
}
{
Error += true == glm::isnan(0.0f/Zero_f) ? 0 : 1;
Error += true == glm::any(glm::isnan(glm::vec2(0.0f/Zero_f))) ? 0 : 1;
Error += true == glm::any(glm::isnan(glm::vec3(0.0f/Zero_f))) ? 0 : 1;
Error += true == glm::any(glm::isnan(glm::vec4(0.0f/Zero_f))) ? 0 : 1;
}
return Error;
}
}//namespace isnan_
namespace isinf_
{
static int test()
{
int Error = 0;
float Zero_f = 0.0;
double Zero_d = 0.0;
{
Error += true == glm::isinf( 1.0/Zero_d) ? 0 : 1;
Error += true == glm::isinf(-1.0/Zero_d) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::dvec2( 1.0/Zero_d))) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::dvec2(-1.0/Zero_d))) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::dvec3( 1.0/Zero_d))) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::dvec3(-1.0/Zero_d))) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::dvec4( 1.0/Zero_d))) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::dvec4(-1.0/Zero_d))) ? 0 : 1;
}
{
Error += true == glm::isinf( 1.0f/Zero_f) ? 0 : 1;
Error += true == glm::isinf(-1.0f/Zero_f) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::vec2( 1.0f/Zero_f))) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::vec2(-1.0f/Zero_f))) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::vec3( 1.0f/Zero_f))) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::vec3(-1.0f/Zero_f))) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::vec4( 1.0f/Zero_f))) ? 0 : 1;
Error += true == glm::any(glm::isinf(glm::vec4(-1.0f/Zero_f))) ? 0 : 1;
}
return Error;
}
}//namespace isinf_
namespace sign
{
template<typename genFIType>
GLM_FUNC_QUALIFIER genFIType sign_if(genFIType x)
{
GLM_STATIC_ASSERT(
std::numeric_limits<genFIType>::is_iec559 ||
(std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer), "'sign' only accept signed inputs");
genFIType result;
if(x > genFIType(0))
result = genFIType(1);
else if(x < genFIType(0))
result = genFIType(-1);
else
result = genFIType(0);
return result;
}
template<typename genFIType>
GLM_FUNC_QUALIFIER genFIType sign_alu1(genFIType x)
{
GLM_STATIC_ASSERT(
std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
"'sign' only accept integer inputs");
return (x >> 31) | (static_cast<unsigned>(-x) >> 31);
}
GLM_FUNC_QUALIFIER int sign_alu2(int x)
{
GLM_STATIC_ASSERT(std::numeric_limits<int>::is_signed && std::numeric_limits<int>::is_integer, "'sign' only accept integer inputs");
# if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(push)
# pragma warning(disable : 4146) //cast truncates constant value
# endif
return -(static_cast<unsigned>(x) >> 31) | (-static_cast<unsigned>(x) >> 31);
# if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(pop)
# endif
}
template<typename genFIType>
GLM_FUNC_QUALIFIER genFIType sign_sub(genFIType x)
{
GLM_STATIC_ASSERT(
std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
"'sign' only accept integer inputs");
return (static_cast<unsigned>(-x) >> 31) - (static_cast<unsigned>(x) >> 31);
}
template<typename genFIType>
GLM_FUNC_QUALIFIER genFIType sign_cmp(genFIType x)
{
GLM_STATIC_ASSERT(
std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
"'sign' only accept integer inputs");
return (x > 0) - (x < 0);
}
template<typename genType>
struct type
{
genType Value;
genType Return;
};
int test_int32()
{
type<glm::int32> const Data[] =
{
{ std::numeric_limits<glm::int32>::max(), 1},
{ std::numeric_limits<glm::int32>::min(), -1},
{ 0, 0},
{ 1, 1},
{ 2, 1},
{ 3, 1},
{-1,-1},
{-2,-1},
{-3,-1}
};
int Error = 0;
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
{
glm::int32 Result = glm::sign(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
{
glm::int32 Result = sign_cmp(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
{
glm::int32 Result = sign_if(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
{
glm::int32 Result = sign_alu1(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
{
glm::int32 Result = sign_alu2(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
int test_i32vec4()
{
type<glm::ivec4> const Data[] =
{
{glm::ivec4( 1), glm::ivec4( 1)},
{glm::ivec4( 0), glm::ivec4( 0)},
{glm::ivec4( 2), glm::ivec4( 1)},
{glm::ivec4( 3), glm::ivec4( 1)},
{glm::ivec4(-1), glm::ivec4(-1)},
{glm::ivec4(-2), glm::ivec4(-1)},
{glm::ivec4(-3), glm::ivec4(-1)}
};
int Error = 0;
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::ivec4>); ++i)
{
glm::ivec4 Result = glm::sign(Data[i].Value);
Error += glm::all(glm::equal(Data[i].Return, Result)) ? 0 : 1;
}
return Error;
}
int test_f32vec4()
{
type<glm::vec4> const Data[] =
{
{glm::vec4( 1), glm::vec4( 1)},
{glm::vec4( 0), glm::vec4( 0)},
{glm::vec4( 2), glm::vec4( 1)},
{glm::vec4( 3), glm::vec4( 1)},
{glm::vec4(-1), glm::vec4(-1)},
{glm::vec4(-2), glm::vec4(-1)},
{glm::vec4(-3), glm::vec4(-1)}
};
int Error = 0;
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::vec4>); ++i)
{
glm::vec4 Result = glm::sign(Data[i].Value);
Error += glm::all(glm::equal(Data[i].Return, Result, glm::epsilon<float>())) ? 0 : 1;
}
return Error;
}
static int test()
{
int Error = 0;
Error += test_int32();
Error += test_i32vec4();
Error += test_f32vec4();
return Error;
}
int perf_rand(std::size_t Samples)
{
int Error = 0;
std::size_t const Count = Samples;
std::vector<glm::int32> Input, Output;
Input.resize(Count);
Output.resize(Count);
for(std::size_t i = 0; i < Count; ++i)
Input[i] = static_cast<glm::int32>(glm::linearRand(-65536.f, 65536.f));
std::clock_t Timestamp0 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = sign_cmp(Input[i]);
std::clock_t Timestamp1 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = sign_if(Input[i]);
std::clock_t Timestamp2 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = sign_alu1(Input[i]);
std::clock_t Timestamp3 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = sign_alu2(Input[i]);
std::clock_t Timestamp4 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = sign_sub(Input[i]);
std::clock_t Timestamp5 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = glm::sign(Input[i]);
std::clock_t Timestamp6 = std::clock();
std::printf("sign_cmp(rand) Time %d clocks\n", static_cast<int>(Timestamp1 - Timestamp0));
std::printf("sign_if(rand) Time %d clocks\n", static_cast<int>(Timestamp2 - Timestamp1));
std::printf("sign_alu1(rand) Time %d clocks\n", static_cast<int>(Timestamp3 - Timestamp2));
std::printf("sign_alu2(rand) Time %d clocks\n", static_cast<int>(Timestamp4 - Timestamp3));
std::printf("sign_sub(rand) Time %d clocks\n", static_cast<int>(Timestamp5 - Timestamp4));
std::printf("glm::sign(rand) Time %d clocks\n", static_cast<int>(Timestamp6 - Timestamp5));
return Error;
}
int perf_linear(std::size_t Samples)
{
int Error = 0;
std::size_t const Count = Samples;
std::vector<glm::int32> Input, Output;
Input.resize(Count);
Output.resize(Count);
for(std::size_t i = 0; i < Count; ++i)
Input[i] = static_cast<glm::int32>(i);
std::clock_t Timestamp0 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = sign_cmp(Input[i]);
std::clock_t Timestamp1 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = sign_if(Input[i]);
std::clock_t Timestamp2 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = sign_alu1(Input[i]);
std::clock_t Timestamp3 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = sign_alu2(Input[i]);
std::clock_t Timestamp4 = std::clock();
for(std::size_t i = 0; i < Count; ++i)
Output[i] = sign_sub(Input[i]);
std::clock_t Timestamp5 = std::clock();
std::printf("sign_cmp(linear) Time %d clocks\n", static_cast<int>(Timestamp1 - Timestamp0));
std::printf("sign_if(linear) Time %d clocks\n", static_cast<int>(Timestamp2 - Timestamp1));
std::printf("sign_alu1(linear) Time %d clocks\n", static_cast<int>(Timestamp3 - Timestamp2));
std::printf("sign_alu2(linear) Time %d clocks\n", static_cast<int>(Timestamp4 - Timestamp3));
std::printf("sign_sub(linear) Time %d clocks\n", static_cast<int>(Timestamp5 - Timestamp4));
return Error;
}
int perf_linear_cal(std::size_t Samples)
{
int Error = 0;
glm::int32 const Count = static_cast<glm::int32>(Samples);
std::clock_t Timestamp0 = std::clock();
glm::int32 Sum = 0;
for(glm::int32 i = 1; i < Count; ++i)
Sum += sign_cmp(i);
std::clock_t Timestamp1 = std::clock();
for(glm::int32 i = 1; i < Count; ++i)
Sum += sign_if(i);
std::clock_t Timestamp2 = std::clock();
for(glm::int32 i = 1; i < Count; ++i)
Sum += sign_alu1(i);
std::clock_t Timestamp3 = std::clock();
for(glm::int32 i = 1; i < Count; ++i)
Sum += sign_alu2(i);
std::clock_t Timestamp4 = std::clock();
for(glm::int32 i = 1; i < Count; ++i)
Sum += sign_sub(i);
std::clock_t Timestamp5 = std::clock();
std::printf("Sum %d\n", static_cast<int>(Sum));
std::printf("sign_cmp(linear_cal) Time %d clocks\n", static_cast<int>(Timestamp1 - Timestamp0));
std::printf("sign_if(linear_cal) Time %d clocks\n", static_cast<int>(Timestamp2 - Timestamp1));
std::printf("sign_alu1(linear_cal) Time %d clocks\n", static_cast<int>(Timestamp3 - Timestamp2));
std::printf("sign_alu2(linear_cal) Time %d clocks\n", static_cast<int>(Timestamp4 - Timestamp3));
std::printf("sign_sub(linear_cal) Time %d clocks\n", static_cast<int>(Timestamp5 - Timestamp4));
return Error;
}
static int perf(std::size_t Samples)
{
int Error(0);
Error += perf_linear_cal(Samples);
Error += perf_linear(Samples);
Error += perf_rand(Samples);
return Error;
}
}//namespace sign
namespace frexp_
{
static int test()
{
int Error = 0;
{
glm::vec1 const x(1024);
glm::ivec1 exp;
glm::vec1 A = glm::frexp(x, exp);
Error += glm::all(glm::equal(A, glm::vec1(0.5), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(exp, glm::ivec1(11))) ? 0 : 1;
}
{
glm::vec2 const x(1024, 0.24);
glm::ivec2 exp;
glm::vec2 A = glm::frexp(x, exp);
Error += glm::all(glm::equal(A, glm::vec2(0.5, 0.96), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(exp, glm::ivec2(11, -2))) ? 0 : 1;
}
{
glm::vec3 const x(1024, 0.24, 0);
glm::ivec3 exp;
glm::vec3 A = glm::frexp(x, exp);
Error += glm::all(glm::equal(A, glm::vec3(0.5, 0.96, 0.0), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(exp, glm::ivec3(11, -2, 0))) ? 0 : 1;
}
{
glm::vec4 const x(1024, 0.24, 0, -1.33);
glm::ivec4 exp;
glm::vec4 A = glm::frexp(x, exp);
Error += glm::all(glm::equal(A, glm::vec4(0.5, 0.96, 0.0, -0.665), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(exp, glm::ivec4(11, -2, 0, 1))) ? 0 : 1;
}
return Error;
}
}//namespace frexp_
namespace ldexp_
{
static int test()
{
int Error(0);
{
glm::vec1 A = glm::vec1(0.5);
glm::ivec1 exp = glm::ivec1(11);
glm::vec1 x = glm::ldexp(A, exp);
Error += glm::all(glm::equal(x, glm::vec1(1024),0.00001f)) ? 0 : 1;
}
{
glm::vec2 A = glm::vec2(0.5, 0.96);
glm::ivec2 exp = glm::ivec2(11, -2);
glm::vec2 x = glm::ldexp(A, exp);
Error += glm::all(glm::equal(x, glm::vec2(1024, .24),0.00001f)) ? 0 : 1;
}
{
glm::vec3 A = glm::vec3(0.5, 0.96, 0.0);
glm::ivec3 exp = glm::ivec3(11, -2, 0);
glm::vec3 x = glm::ldexp(A, exp);
Error += glm::all(glm::equal(x, glm::vec3(1024, .24, 0),0.00001f)) ? 0 : 1;
}
{
glm::vec4 A = glm::vec4(0.5, 0.96, 0.0, -0.665);
glm::ivec4 exp = glm::ivec4(11, -2, 0, 1);
glm::vec4 x = glm::ldexp(A, exp);
Error += glm::all(glm::equal(x, glm::vec4(1024, .24, 0, -1.33),0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace ldexp_
static int test_constexpr()
{
#if GLM_HAS_CONSTEXPR
static_assert(glm::abs(1.0f) > 0.0f, "GLM: Failed constexpr");
constexpr glm::vec1 const A = glm::abs(glm::vec1(1.0f));
constexpr glm::vec2 const B = glm::abs(glm::vec2(1.0f));
constexpr glm::vec3 const C = glm::abs(glm::vec3(1.0f));
constexpr glm::vec4 const D = glm::abs(glm::vec4(1.0f));
#endif // GLM_HAS_CONSTEXPR
return 0;
}
int main()
{
int Error = 0;
Error += test_constexpr();
Error += sign::test();
Error += floor_::test();
Error += mod_::test();
Error += modf_::test();
Error += floatBitsToInt::test();
Error += floatBitsToUint::test();
Error += mix_::test();
Error += step_::test();
Error += max_::test();
Error += min_::test();
Error += clamp_::test();
Error += round_::test();
Error += roundEven::test();
Error += isnan_::test();
Error += isinf_::test();
Error += frexp_::test();
Error += ldexp_::test();
# ifdef NDEBUG
std::size_t Samples = 1000;
# else
std::size_t Samples = 1;
# endif
Error += sign::perf(Samples);
Error += min_::perf(Samples);
return Error;
}
|