153 lines
3.6 KiB
C
153 lines
3.6 KiB
C
/*
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
#include <basic-geometry.h>
|
|
|
|
#ifdef _WIN64
|
|
#include <windows.h>
|
|
#else
|
|
#include <time.h>
|
|
#endif // _WINDOWS_
|
|
|
|
typedef struct {
|
|
BgcVersorFP32 versor1, versor2, result;
|
|
//BgcMatrix3x3FP32 matrix;
|
|
//BgcVector3FP32 vector1, vector2;
|
|
} structure_fp32_t;
|
|
|
|
structure_fp32_t* allocate_structures(const unsigned int amount)
|
|
{
|
|
return calloc(amount, sizeof(structure_fp32_t));
|
|
}
|
|
|
|
structure_fp32_t* make_structures(const unsigned int amount)
|
|
{
|
|
structure_fp32_t* list = allocate_structures(amount);
|
|
|
|
if (list == 0) {
|
|
return 0;
|
|
}
|
|
|
|
const float multiplier = 2.0f / RAND_MAX;
|
|
|
|
for (unsigned int i = 0; i < amount; i++) {
|
|
bgc_versor_set_values_fp32(
|
|
rand() * multiplier - 1.0f,
|
|
rand() * multiplier - 1.0f,
|
|
rand() * multiplier - 1.0f,
|
|
rand() * multiplier - 1.0f,
|
|
&list[i].versor1
|
|
);
|
|
|
|
bgc_versor_set_values_fp32(
|
|
rand() * multiplier - 1.0f,
|
|
rand() * multiplier - 1.0f,
|
|
rand() * multiplier - 1.0f,
|
|
rand() * multiplier - 1.0f,
|
|
&list[i].versor2
|
|
);
|
|
|
|
bgc_versor_reset_fp32(&list[i].result);
|
|
|
|
//bgc_matrix3x3_set_to_identity_fp32(&list[i].matrix);
|
|
/*
|
|
bgc_vector3_set_values_fp32(
|
|
rand() * multiplier - 1.0f,
|
|
rand() * multiplier - 1.0f,
|
|
rand() * multiplier - 1.0f,
|
|
&list[i].vector1
|
|
);
|
|
|
|
bgc_vector3_reset_fp32(&list[i].vector2);
|
|
*//*
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
void print_versor_fp32(const BgcVersorFP32* versor)
|
|
{
|
|
printf("Versor (%f, %f, %f, %f)\n", versor->s0, versor->x1, versor->x2, versor->x3);
|
|
}
|
|
|
|
void print_versor_fp64(const BgcVersorFP64* versor)
|
|
{
|
|
printf("Versor (%lf, %lf, %lf, %lf)\n", versor->s0, versor->x1, versor->x2, versor->x3);
|
|
}
|
|
|
|
void print_vector_fp32(const BgcVector3FP32* vector)
|
|
{
|
|
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, bgc_vector3_get_modulus_fp32(vector));
|
|
}
|
|
|
|
void print_vector_fp64(const BgcVector3FP64* vector)
|
|
{
|
|
printf("(%lf, %lf, %lf) / %lf\n", vector->x1, vector->x2, vector->x3, bgc_vector3_get_modulus_fp64(vector));
|
|
}
|
|
|
|
void list_work(const uint_fast32_t amount, structure_fp32_t* list)
|
|
{
|
|
for (uint_fast32_t j = 0; j < 1000; j++) {
|
|
for (uint_fast32_t i = 0; i < amount; i++) {
|
|
bgc_versor_combine_fp32(&list[i].versor1, &list[i].versor1, &list[i].result);
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
int main()
|
|
{
|
|
const unsigned int amount = 1000000;
|
|
structure_fp32_t* list = make_structures(amount);
|
|
|
|
#ifdef _WIN64
|
|
ULONGLONG start, end;
|
|
|
|
start = GetTickCount64();
|
|
|
|
srand((unsigned int)(start & 0xfffffff));
|
|
|
|
start = GetTickCount64();
|
|
#else
|
|
struct timespec start, end;
|
|
clock_gettime(0, &start);
|
|
srand((unsigned int)(start.tv_nsec & 0xfffffff));
|
|
|
|
clock_gettime(CLOCK_REALTIME, &start);
|
|
#endif // _WIN64
|
|
|
|
list_work(amount, list);
|
|
|
|
#ifdef _WIN64
|
|
end = GetTickCount64();
|
|
|
|
printf("Time: %lld\n", end - start);
|
|
#else
|
|
clock_gettime(CLOCK_REALTIME, &end);
|
|
|
|
printf("Time: %lf\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001);
|
|
#endif // _WIN64
|
|
|
|
print_versor_fp32(&list[10].versor1);
|
|
print_versor_fp32(&list[10].versor2);
|
|
print_versor_fp32(&list[10].result);
|
|
|
|
free(list);
|
|
|
|
return 0;
|
|
}
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <basic-geometry.h>
|
|
|
|
int main()
|
|
{
|
|
BgcVector3FP32 my_vector;
|
|
|
|
bgc_vector3_set_values_fp32(-2, 7, 10, &my_vector);
|
|
|
|
printf("x1 = %f, x2 = %f, x3 = %f\n", my_vector.x1, my_vector.x2, my_vector.x3);
|
|
|
|
return 0;
|
|
}
|