Упорядочивание проекта
This commit is contained in:
parent
0dcd9c0d4d
commit
89dfd7644b
32 changed files with 1730 additions and 1719 deletions
|
|
@ -53,12 +53,12 @@ structure_fp32_t* make_structures(const unsigned int amount)
|
|||
|
||||
void print_versor_fp32(const BgcVersorFP32* versor)
|
||||
{
|
||||
printf("Versor (s0 = %0.12f, x1 = %0.12f, x2 = %0.12f, x3 = %0.12f)\n", versor->s0, versor->x1, versor->x2, versor->x3);
|
||||
printf("Versor (s0 = %0.12f, x1 = %0.12f, x2 = %0.12f, x3 = %0.12f)\n", versor->_s0, versor->_x1, versor->_x2, versor->_x3);
|
||||
}
|
||||
|
||||
void print_versor_fp64(const BgcVersorFP64* versor)
|
||||
{
|
||||
printf("Versor (s0 = %0.20f, x1 = %0.20f, x2 = %0.20f, x3 = %0.20f)\n", versor->s0, versor->x1, versor->x2, versor->x3);
|
||||
printf("Versor (s0 = %0.20f, x1 = %0.20f, x2 = %0.20f, x3 = %0.20f)\n", versor->_s0, versor->_x1, versor->_x2, versor->_x3);
|
||||
}
|
||||
|
||||
void print_vector_fp32(const BgcVector3FP32* vector)
|
||||
|
|
@ -469,11 +469,16 @@ void test_basis_difference_fp64()
|
|||
print_versor_fp64(&turn);
|
||||
}
|
||||
|
||||
typedef union {
|
||||
int si32;
|
||||
float fp32;
|
||||
} uni_number;
|
||||
|
||||
int main()
|
||||
{
|
||||
//BgcVersorFP32 start = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
//BgcVersorFP32 end = { 0.0f, 1.0f, 0.0f, 0.0f };
|
||||
|
||||
/*
|
||||
BgcVersorFP32 start = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
BgcVersorFP32 end = { 0.9999f, 0.01414f, 0.0f, 0.0f };
|
||||
BgcSlerpFP32 slerp;
|
||||
|
|
@ -482,8 +487,14 @@ int main()
|
|||
bgc_slerp_get_turn_for_phase_fp32(&slerp, 0.5f, &result);
|
||||
|
||||
print_versor_fp32(&result);
|
||||
|
||||
*/
|
||||
//test_basis_difference_fp64();
|
||||
|
||||
uni_number number;
|
||||
|
||||
number.fp32 = 2.0f;
|
||||
|
||||
printf("%x\n", number.si32);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,35 +159,6 @@ void test_complex_subtract_fp32()
|
|||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_subtract_scaled_fp32()
|
||||
{
|
||||
BgcComplexFP32 vector1, vector2, result;
|
||||
|
||||
print_testing_name("bgc_complex_subtract_scaled_fp32");
|
||||
|
||||
bgc_complex_set_values_fp32(10.0f, -20.0f, &vector1);
|
||||
bgc_complex_set_values_fp32(4.0f, 5.0f, &vector2);
|
||||
|
||||
bgc_complex_subtract_scaled_fp32(&vector1, &vector2, 2.0f, &result);
|
||||
|
||||
if (!bgc_are_close_fp32(result.real, 2.0f) || !bgc_are_close_fp32(result.imaginary, -30.0f)) {
|
||||
print_testing_error("first test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_complex_set_values_fp32(0.36f, 100.4f, &vector1);
|
||||
bgc_complex_set_values_fp32(1.09f, 0.1f, &vector2);
|
||||
|
||||
bgc_complex_subtract_scaled_fp32(&vector1, &vector2, 4.0f, &result);
|
||||
|
||||
if (!bgc_are_close_fp32(result.real, -4.0f) || !bgc_are_close_fp32(result.imaginary, 100.0f)) {
|
||||
print_testing_error("second test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_subtract_fp64()
|
||||
{
|
||||
BgcComplexFP64 vector1, vector2, result;
|
||||
|
|
@ -217,42 +188,10 @@ void test_complex_subtract_fp64()
|
|||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_subtract_scaled_fp64()
|
||||
{
|
||||
BgcComplexFP64 vector1, vector2, result;
|
||||
|
||||
print_testing_name("bgc_complex_subtract_scaled_fp64");
|
||||
|
||||
bgc_complex_set_values_fp64(10.0, 20.0, &vector1);
|
||||
bgc_complex_set_values_fp64(4.0, 5.0, &vector2);
|
||||
|
||||
bgc_complex_subtract_scaled_fp64(&vector1, &vector2, 2.5, &result);
|
||||
|
||||
if (!bgc_are_close_fp64(result.real, 0.0) || !bgc_are_close_fp64(result.imaginary, 7.5)) {
|
||||
print_testing_error("first test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_complex_set_values_fp64(-0.27, 100.3, &vector1);
|
||||
bgc_complex_set_values_fp64(-1.29, -0.1, &vector2);
|
||||
|
||||
bgc_complex_subtract_scaled_fp64(&vector1, &vector2, 3.0, &result);
|
||||
|
||||
if (!bgc_are_close_fp64(result.real, 3.6) || !bgc_are_close_fp64(result.imaginary, 100.6)) {
|
||||
print_testing_error("second test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_subtract()
|
||||
{
|
||||
test_complex_subtract_fp32();
|
||||
test_complex_subtract_fp64();
|
||||
|
||||
test_complex_subtract_scaled_fp32();
|
||||
test_complex_subtract_scaled_fp64();
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
|
@ -265,7 +204,7 @@ void test_complex_multiply_fp32()
|
|||
|
||||
bgc_complex_set_values_fp32(10.0f, -20.0f, &vector);
|
||||
|
||||
bgc_complex_multiply_fp32(&vector, 0.5f, &result);
|
||||
bgc_complex_multiply_by_number_fp32(&vector, 0.5f, &result);
|
||||
|
||||
if (!bgc_are_close_fp32(result.real, 5.0f) || !bgc_are_close_fp32(result.imaginary, -10.0f)) {
|
||||
print_testing_error("first test failed");
|
||||
|
|
@ -274,7 +213,7 @@ void test_complex_multiply_fp32()
|
|||
|
||||
bgc_complex_set_values_fp32(1.78f, -0.1f, &vector);
|
||||
|
||||
bgc_complex_multiply_fp32(&vector, 2.0f, &result);
|
||||
bgc_complex_multiply_by_number_fp32(&vector, 2.0f, &result);
|
||||
|
||||
if (!bgc_are_close_fp32(result.real, 3.56f) || !bgc_are_close_fp32(result.imaginary, -0.2f)) {
|
||||
print_testing_error("second test failed");
|
||||
|
|
@ -292,7 +231,7 @@ void test_complex_multiply_fp64()
|
|||
|
||||
bgc_complex_set_values_fp64(30.0, -10.0, &vector);
|
||||
|
||||
bgc_complex_multiply_fp64(&vector, 0.3, &result);
|
||||
bgc_complex_multiply_by_number_fp64(&vector, 0.3, &result);
|
||||
|
||||
if (!bgc_are_close_fp64(result.real, 9.0) || !bgc_are_close_fp64(result.imaginary, -3.0)) {
|
||||
print_testing_error("first test failed");
|
||||
|
|
@ -301,7 +240,7 @@ void test_complex_multiply_fp64()
|
|||
|
||||
bgc_complex_set_values_fp64(1.18, -0.25, &vector);
|
||||
|
||||
bgc_complex_multiply_fp64(&vector, 4.0, &result);
|
||||
bgc_complex_multiply_by_number_fp64(&vector, 4.0, &result);
|
||||
|
||||
if (!bgc_are_close_fp64(result.real, 4.72) || !bgc_are_close_fp64(result.imaginary, -1.0)) {
|
||||
print_testing_error("second test failed");
|
||||
|
|
@ -327,7 +266,7 @@ void test_complex_divide_fp32()
|
|||
|
||||
bgc_complex_set_values_fp32(10.0f, -20.0f, &vector);
|
||||
|
||||
bgc_complex_divide_fp32(&vector, 10.0f, &result);
|
||||
bgc_complex_divide_by_number_fp32(&vector, 10.0f, &result);
|
||||
|
||||
if (!bgc_are_close_fp32(result.real, 1.0f) || !bgc_are_close_fp32(result.imaginary, -2.0f)) {
|
||||
print_testing_error("first test failed");
|
||||
|
|
@ -336,7 +275,7 @@ void test_complex_divide_fp32()
|
|||
|
||||
bgc_complex_set_values_fp32(1.78f, -0.1f, &vector);
|
||||
|
||||
bgc_complex_divide_fp32(&vector, 0.2f, &result);
|
||||
bgc_complex_divide_by_number_fp32(&vector, 0.2f, &result);
|
||||
|
||||
if (!bgc_are_close_fp32(result.real, 8.9f) || !bgc_are_close_fp32(result.imaginary, -0.5f)) {
|
||||
print_testing_error("second test failed");
|
||||
|
|
@ -354,7 +293,7 @@ void test_complex_divide_fp64()
|
|||
|
||||
bgc_complex_set_values_fp64(30.0, -10.0, &vector);
|
||||
|
||||
bgc_complex_divide_fp64(&vector, 5.0, &result);
|
||||
bgc_complex_divide_by_number_fp64(&vector, 5.0, &result);
|
||||
|
||||
if (!bgc_are_close_fp64(result.real, 6.0) || !bgc_are_close_fp64(result.imaginary, -2.0)) {
|
||||
print_testing_error("first test failed");
|
||||
|
|
@ -363,7 +302,7 @@ void test_complex_divide_fp64()
|
|||
|
||||
bgc_complex_set_values_fp64(1.18, -0.25, &vector);
|
||||
|
||||
bgc_complex_divide_fp64(&vector, 0.5, &result);
|
||||
bgc_complex_divide_by_number_fp64(&vector, 0.5, &result);
|
||||
|
||||
if (!bgc_are_close_fp64(result.real, 2.36) || !bgc_are_close_fp64(result.imaginary, -0.5)) {
|
||||
print_testing_error("second test failed");
|
||||
|
|
|
|||
|
|
@ -17,12 +17,8 @@ void test_complex_add();
|
|||
|
||||
void test_complex_subtract_fp32();
|
||||
|
||||
void test_complex_subtract_scaled_fp32();
|
||||
|
||||
void test_complex_subtract_fp64();
|
||||
|
||||
void test_complex_subtract_scaled_fp64();
|
||||
|
||||
void test_complex_subtract();
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ void test_quaternion_set_to_identity_fp32()
|
|||
|
||||
print_testing_name("bgc_quaternion_set_to_identity_fp32");
|
||||
|
||||
bgc_quaternion_set_to_identity_fp32(&vector);
|
||||
bgc_quaternion_make_unit_fp32(&vector);
|
||||
|
||||
if (vector.s0 != 1.0f || vector.x1 != 0.0f || vector.x2 != 0.0f || vector.x3 != 0.0f) {
|
||||
print_testing_failed();
|
||||
|
|
@ -24,7 +24,7 @@ void test_quaternion_set_to_identity_fp64()
|
|||
|
||||
print_testing_name("bgc_quaternion_set_to_identity_fp64");
|
||||
|
||||
bgc_quaternion_set_to_identity_fp64(&vector);
|
||||
bgc_quaternion_make_unit_fp64(&vector);
|
||||
|
||||
if (vector.s0 != 1.0 || vector.x1 != 0.0 || vector.x2 != 0.0 || vector.x3 != 0.0) {
|
||||
print_testing_failed();
|
||||
|
|
|
|||
|
|
@ -159,35 +159,6 @@ void test_vector2_subtract_fp32()
|
|||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_vector2_subtract_scaled_fp32()
|
||||
{
|
||||
BgcVector2FP32 vector1, vector2, result;
|
||||
|
||||
print_testing_name("bgc_vector2_subtract_scaled_fp32");
|
||||
|
||||
bgc_vector2_set_values_fp32(10.0f, -20.0f, &vector1);
|
||||
bgc_vector2_set_values_fp32(4.0f, 5.0f, &vector2);
|
||||
|
||||
bgc_vector2_subtract_scaled_fp32(&vector1, &vector2, 2.0f, &result);
|
||||
|
||||
if (!bgc_are_close_fp32(result.x1, 2.0f) || !bgc_are_close_fp32(result.x2, -30.0f)) {
|
||||
print_testing_error("first test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_vector2_set_values_fp32(0.36f, 100.4f, &vector1);
|
||||
bgc_vector2_set_values_fp32(1.09f, 0.1f, &vector2);
|
||||
|
||||
bgc_vector2_subtract_scaled_fp32(&vector1, &vector2, 4.0f, &result);
|
||||
|
||||
if (!bgc_are_close_fp32(result.x1, -4.0f) || !bgc_are_close_fp32(result.x2, 100.0f)) {
|
||||
print_testing_error("second test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_vector2_subtract_fp64()
|
||||
{
|
||||
BgcVector2FP64 vector1, vector2, result;
|
||||
|
|
@ -217,42 +188,10 @@ void test_vector2_subtract_fp64()
|
|||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_vector2_subtract_scaled_fp64()
|
||||
{
|
||||
BgcVector2FP64 vector1, vector2, result;
|
||||
|
||||
print_testing_name("bgc_vector2_subtract_scaled_fp64");
|
||||
|
||||
bgc_vector2_set_values_fp64(10.0, 20.0, &vector1);
|
||||
bgc_vector2_set_values_fp64(4.0, 5.0, &vector2);
|
||||
|
||||
bgc_vector2_subtract_scaled_fp64(&vector1, &vector2, 2.5, &result);
|
||||
|
||||
if (!bgc_are_close_fp64(result.x1, 0.0) || !bgc_are_close_fp64(result.x2, 7.5)) {
|
||||
print_testing_error("first test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_vector2_set_values_fp64(-0.27, 100.3, &vector1);
|
||||
bgc_vector2_set_values_fp64(-1.29, -0.1, &vector2);
|
||||
|
||||
bgc_vector2_subtract_scaled_fp64(&vector1, &vector2, 3.0, &result);
|
||||
|
||||
if (!bgc_are_close_fp64(result.x1, 3.6) || !bgc_are_close_fp64(result.x2, 100.6)) {
|
||||
print_testing_error("second test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_vector2_subtract()
|
||||
{
|
||||
test_vector2_subtract_fp32();
|
||||
test_vector2_subtract_fp64();
|
||||
|
||||
test_vector2_subtract_scaled_fp32();
|
||||
test_vector2_subtract_scaled_fp64();
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
|
|
|||
|
|
@ -17,12 +17,8 @@ void test_vector2_add();
|
|||
|
||||
void test_vector2_subtract_fp32();
|
||||
|
||||
void test_vector2_subtract_scaled_fp32();
|
||||
|
||||
void test_vector2_subtract_fp64();
|
||||
|
||||
void test_vector2_subtract_scaled_fp64();
|
||||
|
||||
void test_vector2_subtract();
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
|
|
|||
|
|
@ -159,35 +159,6 @@ void test_vector3_subtract_fp32()
|
|||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_vector3_subtract_scaled_fp32()
|
||||
{
|
||||
BgcVector3FP32 vector1, vector2, result;
|
||||
|
||||
print_testing_name("bgc_vector3_subtract_scaled_fp32");
|
||||
|
||||
bgc_vector3_set_values_fp32(10.0f, -20.0f, 1.25f, &vector1);
|
||||
bgc_vector3_set_values_fp32(4.0f, 5.0f, -0.4f, &vector2);
|
||||
|
||||
bgc_vector3_subtract_scaled_fp32(&vector1, &vector2, 2.0f, &result);
|
||||
|
||||
if (!bgc_are_close_fp32(result.x1, 2.0f) || !bgc_are_close_fp32(result.x2, -30.0f) || !bgc_are_close_fp32(result.x3, 2.05f)) {
|
||||
print_testing_error("first test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_vector3_set_values_fp32(0.36f, 100.4f, 10, &vector1);
|
||||
bgc_vector3_set_values_fp32(1.09f, 0.1f, 2.5f, &vector2);
|
||||
|
||||
bgc_vector3_subtract_scaled_fp32(&vector1, &vector2, 4.0f, &result);
|
||||
|
||||
if (!bgc_are_close_fp32(result.x1, -4.0f) || !bgc_are_close_fp32(result.x2, 100.0f) || !bgc_are_close_fp32(result.x3, 0.0f)) {
|
||||
print_testing_error("second test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_vector3_subtract_fp64()
|
||||
{
|
||||
BgcVector3FP64 vector1, vector2, result;
|
||||
|
|
@ -217,42 +188,10 @@ void test_vector3_subtract_fp64()
|
|||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_vector3_subtract_scaled_fp64()
|
||||
{
|
||||
BgcVector3FP64 vector1, vector2, result;
|
||||
|
||||
print_testing_name("bgc_vector3_subtract_scaled_fp64");
|
||||
|
||||
bgc_vector3_set_values_fp64(10.0, 20.0, 0.1, &vector1);
|
||||
bgc_vector3_set_values_fp64(4.0, 5.0, -4.0, &vector2);
|
||||
|
||||
bgc_vector3_subtract_scaled_fp64(&vector1, &vector2, 2.5, &result);
|
||||
|
||||
if (!bgc_are_close_fp64(result.x1, 0.0) || !bgc_are_close_fp64(result.x2, 7.5) || !bgc_are_close_fp64(result.x3, 10.1)) {
|
||||
print_testing_error("first test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_vector3_set_values_fp64(-0.27, 100.3, -0.01, &vector1);
|
||||
bgc_vector3_set_values_fp64(-1.29, -0.1, 0.33, &vector2);
|
||||
|
||||
bgc_vector3_subtract_scaled_fp64(&vector1, &vector2, 3.0, &result);
|
||||
|
||||
if (!bgc_are_close_fp64(result.x1, 3.6) || !bgc_are_close_fp64(result.x2, 100.6) || !bgc_are_close_fp64(result.x3, -1.0)) {
|
||||
print_testing_error("second test failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_vector3_subtract()
|
||||
{
|
||||
test_vector3_subtract_fp32();
|
||||
test_vector3_subtract_fp64();
|
||||
|
||||
test_vector3_subtract_scaled_fp32();
|
||||
test_vector3_subtract_scaled_fp64();
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ void test_versor_copy_fp32()
|
|||
|
||||
bgc_versor_copy_fp32(&_TEST_FP32_VERSOR_LIST[i], &versor);
|
||||
|
||||
if (versor.s0 != _TEST_FP32_VERSOR_LIST[i].s0 ||
|
||||
versor.x1 != _TEST_FP32_VERSOR_LIST[i].x1 ||
|
||||
versor.x2 != _TEST_FP32_VERSOR_LIST[i].x2 ||
|
||||
versor.x3 != _TEST_FP32_VERSOR_LIST[i].x3) {
|
||||
if (versor._s0 != _TEST_FP32_VERSOR_LIST[i]._s0 ||
|
||||
versor._x1 != _TEST_FP32_VERSOR_LIST[i]._x1 ||
|
||||
versor._x2 != _TEST_FP32_VERSOR_LIST[i]._x2 ||
|
||||
versor._x3 != _TEST_FP32_VERSOR_LIST[i]._x3) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
|
|
@ -64,10 +64,10 @@ void test_versor_copy_fp64()
|
|||
|
||||
bgc_versor_copy_fp64(&_TEST_FP64_VERSOR_LIST[i], &versor);
|
||||
|
||||
if (versor.s0 != _TEST_FP64_VERSOR_LIST[i].s0 ||
|
||||
versor.x1 != _TEST_FP64_VERSOR_LIST[i].x1 ||
|
||||
versor.x2 != _TEST_FP64_VERSOR_LIST[i].x2 ||
|
||||
versor.x3 != _TEST_FP64_VERSOR_LIST[i].x3) {
|
||||
if (versor._s0 != _TEST_FP64_VERSOR_LIST[i]._s0 ||
|
||||
versor._x1 != _TEST_FP64_VERSOR_LIST[i]._x1 ||
|
||||
versor._x2 != _TEST_FP64_VERSOR_LIST[i]._x2 ||
|
||||
versor._x3 != _TEST_FP64_VERSOR_LIST[i]._x3) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ void test_versor_reset_fp32()
|
|||
|
||||
bgc_versor_reset_fp32(&versor);
|
||||
|
||||
if (versor.s0 != 1.0f || versor.x1 != 0.0f || versor.x2 != 0.0f || versor.x3 != 0.0f) {
|
||||
if (versor._s0 != 1.0f || versor._x1 != 0.0f || versor._x2 != 0.0f || versor._x3 != 0.0f) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ void test_versor_reset_fp64()
|
|||
|
||||
bgc_versor_reset_fp64(&versor);
|
||||
|
||||
if (versor.s0 != 1.0 || versor.x1 != 0.0 || versor.x2 != 0.0 || versor.x3 != 0.0) {
|
||||
if (versor._s0 != 1.0 || versor._x1 != 0.0 || versor._x2 != 0.0 || versor._x3 != 0.0) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ void test_versor_set_values_fp32()
|
|||
&versor
|
||||
);
|
||||
|
||||
versor_module = sqrtf(versor.s0 * versor.s0 + versor.x1 * versor.x1 + versor.x2 * versor.x2 + versor.x3 * versor.x3);
|
||||
versor_module = sqrtf(versor._s0 * versor._s0 + versor._x1 * versor._x1 + versor._x2 * versor._x2 + versor._x3 * versor._x3);
|
||||
|
||||
if (!bgc_is_unit_fp32(versor_module)) {
|
||||
print_testing_error("Versor module is not equal to one.");
|
||||
|
|
@ -41,19 +41,19 @@ void test_versor_set_values_fp32()
|
|||
continue;
|
||||
}
|
||||
|
||||
ratio = _TEST_FP32_VERSOR_DATA_LIST[i].s0 / versor.s0;
|
||||
ratio = _TEST_FP32_VERSOR_DATA_LIST[i].s0 / versor._s0;
|
||||
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x1 / versor.x1)) {
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x1 / versor._x1)) {
|
||||
print_testing_error("Versor was not normalized proportionally (x1).");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x2 / versor.x2)) {
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x2 / versor._x2)) {
|
||||
print_testing_error("Versor was not normalized proportionally (x2).");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x3 / versor.x3)) {
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x3 / versor._x3)) {
|
||||
print_testing_error("Versor was not normalized proportionally (x3).");
|
||||
return;
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ void test_versor_set_values_fp64()
|
|||
&versor
|
||||
);
|
||||
|
||||
versor_module = sqrt(versor.s0 * versor.s0 + versor.x1 * versor.x1 + versor.x2 * versor.x2 + versor.x3 * versor.x3);
|
||||
versor_module = sqrt(versor._s0 * versor._s0 + versor._x1 * versor._x1 + versor._x2 * versor._x2 + versor._x3 * versor._x3);
|
||||
|
||||
if (!bgc_is_unit_fp64(versor_module)) {
|
||||
print_testing_error("Versor module is not equal to one.");
|
||||
|
|
@ -99,19 +99,19 @@ void test_versor_set_values_fp64()
|
|||
continue;
|
||||
}
|
||||
|
||||
ratio = _TEST_FP64_VERSOR_DATA_LIST[i].s0 / versor.s0;
|
||||
ratio = _TEST_FP64_VERSOR_DATA_LIST[i].s0 / versor._s0;
|
||||
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x1 / versor.x1)) {
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x1 / versor._x1)) {
|
||||
print_testing_error("Versor was not normalized proportionally (x1).");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x2 / versor.x2)) {
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x2 / versor._x2)) {
|
||||
print_testing_error("Versor was not normalized proportionally (x2).");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x3 / versor.x3)) {
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x3 / versor._x3)) {
|
||||
print_testing_error("Versor was not normalized proportionally (x3).");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ void test_versor_swap_fp32()
|
|||
|
||||
bgc_versor_swap_fp32(&versor1b, &versor2b);
|
||||
|
||||
if (versor1a.s0 != versor2b.s0 || versor1a.x1 != versor2b.x1 || versor1a.x2 != versor2b.x2 || versor1a.x3 != versor2b.x3 ||
|
||||
versor2a.s0 != versor1b.s0 || versor2a.x1 != versor1b.x1 || versor2a.x2 != versor1b.x2 || versor2a.x3 != versor1b.x3) {
|
||||
if (versor1a._s0 != versor2b._s0 || versor1a._x1 != versor2b._x1 || versor1a._x2 != versor2b._x2 || versor1a._x3 != versor2b._x3 ||
|
||||
versor2a._s0 != versor1b._s0 || versor2a._x1 != versor1b._x1 || versor2a._x2 != versor1b._x2 || versor2a._x3 != versor1b._x3) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
|
|
@ -88,8 +88,8 @@ void test_versor_swap_fp64()
|
|||
|
||||
bgc_versor_swap_fp64(&versor1b, &versor2b);
|
||||
|
||||
if (versor1a.s0 != versor2b.s0 || versor1a.x1 != versor2b.x1 || versor1a.x2 != versor2b.x2 || versor1a.x3 != versor2b.x3 ||
|
||||
versor2a.s0 != versor1b.s0 || versor2a.x1 != versor1b.x1 || versor2a.x2 != versor1b.x2 || versor2a.x3 != versor1b.x3) {
|
||||
if (versor1a._s0 != versor2b._s0 || versor1a._x1 != versor2b._x1 || versor1a._x2 != versor2b._x2 || versor1a._x3 != versor2b._x3 ||
|
||||
versor2a._s0 != versor1b._s0 || versor2a._x1 != versor1b._x1 || versor2a._x2 != versor1b._x2 || versor2a._x3 != versor1b._x3) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
<ClInclude Include="matrixes.h" />
|
||||
<ClInclude Include="quaternion.h" />
|
||||
<ClInclude Include="rotation3.h" />
|
||||
<ClInclude Include="types.h" />
|
||||
<ClInclude Include="utilities.h" />
|
||||
<ClInclude Include="slerp.h" />
|
||||
<ClInclude Include="versor.h" />
|
||||
|
|
|
|||
|
|
@ -69,6 +69,9 @@
|
|||
<ClInclude Include="slerp.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="types.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="angle.c">
|
||||
|
|
|
|||
|
|
@ -27,23 +27,35 @@ extern inline void bgc_complex_swap_fp64(BgcComplexFP64* number1, BgcComplexFP64
|
|||
extern inline void bgc_complex_convert_fp64_to_fp32(const BgcComplexFP64* source, BgcComplexFP32* destination);
|
||||
extern inline void bgc_complex_convert_fp32_to_fp64(const BgcComplexFP32* source, BgcComplexFP64* destination);
|
||||
|
||||
extern inline void bgc_complex_reverse_fp32(const BgcComplexFP32* number, BgcComplexFP32* reverse);
|
||||
extern inline void bgc_complex_reverse_fp64(const BgcComplexFP64* number, BgcComplexFP64* reverse);
|
||||
extern inline void bgc_complex_make_opposite_fp32(BgcComplexFP32* number);
|
||||
extern inline void bgc_complex_make_opposite_fp64(BgcComplexFP64* number);
|
||||
|
||||
extern inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP32* normalized);
|
||||
extern inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP64* normalized);
|
||||
extern inline void bgc_complex_get_opposite_fp32(const BgcComplexFP32* number, BgcComplexFP32* opposite);
|
||||
extern inline void bgc_complex_get_opposite_fp64(const BgcComplexFP64* number, BgcComplexFP64* opposite);
|
||||
|
||||
extern inline void bgc_complex_conjugate_fp32(const BgcComplexFP32* number, BgcComplexFP32* conjugate);
|
||||
extern inline void bgc_complex_conjugate_fp64(const BgcComplexFP64* number, BgcComplexFP64* conjugate);
|
||||
extern inline int bgc_complex_normalize_fp32(BgcComplexFP32* number);
|
||||
extern inline int bgc_complex_normalize_fp64(BgcComplexFP64* number);
|
||||
|
||||
extern inline int bgc_complex_invert_fp32(const BgcComplexFP32* number, BgcComplexFP32* inverted);
|
||||
extern inline int bgc_complex_invert_fp64(const BgcComplexFP64* number, BgcComplexFP64* inverted);
|
||||
extern inline int bgc_complex_get_normalized_fp32(const BgcComplexFP32* number, BgcComplexFP32* normalized);
|
||||
extern inline int bgc_complex_get_normalized_fp64(const BgcComplexFP64* number, BgcComplexFP64* normalized);
|
||||
|
||||
extern inline void bgc_complex_get_product_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* result);
|
||||
extern inline void bgc_complex_get_product_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* result);
|
||||
extern inline void bgc_complex_conjugate_fp32(BgcComplexFP32* number);
|
||||
extern inline void bgc_complex_conjugate_fp64(BgcComplexFP64* number);
|
||||
|
||||
extern inline int bgc_complex_get_ratio_fp32(const BgcComplexFP32* divident, const BgcComplexFP32* divisor, BgcComplexFP32* quotient);
|
||||
extern inline int bgc_complex_get_ratio_fp64(const BgcComplexFP64* divident, const BgcComplexFP64* divisor, BgcComplexFP64* quotient);
|
||||
extern inline void bgc_complex_get_conjugate_fp32(const BgcComplexFP32* number, BgcComplexFP32* conjugate);
|
||||
extern inline void bgc_complex_get_conjugate_fp64(const BgcComplexFP64* number, BgcComplexFP64* conjugate);
|
||||
|
||||
extern inline int bgc_complex_invert_fp32(BgcComplexFP32* number);
|
||||
extern inline int bgc_complex_invert_fp64(BgcComplexFP64* number);
|
||||
|
||||
extern inline int bgc_complex_get_inverse_fp32(const BgcComplexFP32* number, BgcComplexFP32* inverse);
|
||||
extern inline int bgc_complex_get_inverse_fp64(const BgcComplexFP64* number, BgcComplexFP64* inverse);
|
||||
|
||||
extern inline void bgc_complex_multiply_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* result);
|
||||
extern inline void bgc_complex_multiply_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* result);
|
||||
|
||||
extern inline int bgc_complex_devide_fp32(const BgcComplexFP32* divident, const BgcComplexFP32* divisor, BgcComplexFP32* quotient);
|
||||
extern inline int bgc_complex_devide_fp64(const BgcComplexFP64* divident, const BgcComplexFP64* divisor, BgcComplexFP64* quotient);
|
||||
|
||||
extern inline void bgc_complex_add_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* sum);
|
||||
extern inline void bgc_complex_add_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* sum);
|
||||
|
|
@ -54,13 +66,10 @@ extern inline void bgc_complex_add_scaled_fp64(const BgcComplexFP64* basic_numbe
|
|||
extern inline void bgc_complex_subtract_fp32(const BgcComplexFP32* minuend, const BgcComplexFP32* subtrahend, BgcComplexFP32* difference);
|
||||
extern inline void bgc_complex_subtract_fp64(const BgcComplexFP64* minuend, const BgcComplexFP64* subtrahend, BgcComplexFP64* difference);
|
||||
|
||||
extern inline void bgc_complex_subtract_scaled_fp32(const BgcComplexFP32* basic_number, const BgcComplexFP32* scalable_number, const float scale, BgcComplexFP32* difference);
|
||||
extern inline void bgc_complex_subtract_scaled_fp64(const BgcComplexFP64* basic_number, const BgcComplexFP64* scalable_number, const double scale, BgcComplexFP64* difference);
|
||||
|
||||
extern inline void bgc_complex_multiply_fp32(const BgcComplexFP32* multiplicand, const float multiplier, BgcComplexFP32* product);
|
||||
extern inline void bgc_complex_multiply_by_number_fp32(const BgcComplexFP32* multiplicand, const float multiplier, BgcComplexFP32* product);
|
||||
extern inline void bgc_complex_multiply_fp64(const BgcComplexFP64* multiplicand, const double multiplier, BgcComplexFP64* product);
|
||||
|
||||
extern inline void bgc_complex_divide_fp32(const BgcComplexFP32* dividend, const float divisor, BgcComplexFP32* quotient);
|
||||
extern inline void bgc_complex_divide_by_number_fp32(const BgcComplexFP32* dividend, const float divisor, BgcComplexFP32* quotient);
|
||||
extern inline void bgc_complex_divide_fp64(const BgcComplexFP64* dividend, const double divisor, BgcComplexFP64* quotient);
|
||||
|
||||
extern inline void bgc_complex_get_mean_of_two_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* mean);
|
||||
|
|
@ -69,14 +78,8 @@ extern inline void bgc_complex_get_mean_of_two_fp64(const BgcComplexFP64* number
|
|||
extern inline void bgc_complex_get_mean_of_three_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const BgcComplexFP32* number3, BgcComplexFP32* mean);
|
||||
extern inline void bgc_complex_get_mean_of_three_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const BgcComplexFP64* number3, BgcComplexFP64* mean);
|
||||
|
||||
extern inline void bgc_complex_interpolate_linearly_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation);
|
||||
extern inline void bgc_complex_interpolate_linearly_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const double phase, BgcComplexFP64* interpolation);
|
||||
|
||||
extern inline void bgc_complex_minimize_fp32(const BgcComplexFP32* number, BgcComplexFP32* minimal);
|
||||
extern inline void bgc_complex_minimize_fp64(const BgcComplexFP64* number, BgcComplexFP64* minimal);
|
||||
|
||||
extern inline void bgc_complex_maximize_fp32(const BgcComplexFP32* number, BgcComplexFP32* maximal);
|
||||
extern inline void bgc_complex_maximize_fp64(const BgcComplexFP64* number, BgcComplexFP64* maximal);
|
||||
extern inline void bgc_complex_interpolate_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation);
|
||||
extern inline void bgc_complex_interpolate_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const double phase, BgcComplexFP64* interpolation);
|
||||
|
||||
extern inline int bgc_complex_are_close_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2);
|
||||
extern inline int bgc_complex_are_close_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2);
|
||||
|
|
|
|||
|
|
@ -142,23 +142,75 @@ inline void bgc_complex_convert_fp32_to_fp64(const BgcComplexFP32* source, BgcCo
|
|||
destination->imaginary = source->imaginary;
|
||||
}
|
||||
|
||||
// ================== Reverse =================== //
|
||||
// ================== Negative ================== //
|
||||
|
||||
inline void bgc_complex_reverse_fp32(const BgcComplexFP32* number, BgcComplexFP32* reverse)
|
||||
inline void bgc_complex_make_opposite_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
reverse->real = -number->real;
|
||||
reverse->imaginary = -number->imaginary;
|
||||
number->real = -number->real;
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_reverse_fp64(const BgcComplexFP64* number, BgcComplexFP64* reverse)
|
||||
inline void bgc_complex_make_opposite_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
reverse->real = -number->real;
|
||||
reverse->imaginary = -number->imaginary;
|
||||
number->real = -number->real;
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_opposite_fp32(const BgcComplexFP32* number, BgcComplexFP32* opposite)
|
||||
{
|
||||
opposite->real = -number->real;
|
||||
opposite->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_opposite_fp64(const BgcComplexFP64* number, BgcComplexFP64* opposite)
|
||||
{
|
||||
opposite->real = -number->real;
|
||||
opposite->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP32* normalized)
|
||||
inline int bgc_complex_normalize_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(number);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplicand = sqrtf(1.0f / square_modulus);
|
||||
|
||||
number->real *= multiplicand;
|
||||
number->imaginary *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_normalize_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(number);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplicand = sqrt(1.0 / square_modulus);
|
||||
|
||||
number->real *= multiplicand;
|
||||
number->imaginary *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_get_normalized_fp32(const BgcComplexFP32* number, BgcComplexFP32* normalized)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(number);
|
||||
|
||||
|
|
@ -169,6 +221,8 @@ inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP
|
|||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
normalized->real = 0.0f;
|
||||
normalized->imaginary = 0.0f;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +234,7 @@ inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP
|
|||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP64* normalized)
|
||||
inline int bgc_complex_get_normalized_fp64(const BgcComplexFP64* number, BgcComplexFP64* normalized)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(number);
|
||||
|
||||
|
|
@ -191,6 +245,8 @@ inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP
|
|||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
normalized->real = 0.0;
|
||||
normalized->imaginary = 0.0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -204,13 +260,23 @@ inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP
|
|||
|
||||
// ================= Conjugate ================== //
|
||||
|
||||
inline void bgc_complex_conjugate_fp32(const BgcComplexFP32* number, BgcComplexFP32* conjugate)
|
||||
inline void bgc_complex_conjugate_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_conjugate_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_conjugate_fp32(const BgcComplexFP32* number, BgcComplexFP32* conjugate)
|
||||
{
|
||||
conjugate->real = number->real;
|
||||
conjugate->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_conjugate_fp64(const BgcComplexFP64* number, BgcComplexFP64* conjugate)
|
||||
inline void bgc_complex_get_conjugate_fp64(const BgcComplexFP64* number, BgcComplexFP64* conjugate)
|
||||
{
|
||||
conjugate->real = number->real;
|
||||
conjugate->imaginary = -number->imaginary;
|
||||
|
|
@ -218,7 +284,7 @@ inline void bgc_complex_conjugate_fp64(const BgcComplexFP64* number, BgcComplexF
|
|||
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline int bgc_complex_invert_fp32(const BgcComplexFP32* number, BgcComplexFP32* inverted)
|
||||
inline int bgc_complex_get_inverse_fp32(const BgcComplexFP32* number, BgcComplexFP32* inverse)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(number);
|
||||
|
||||
|
|
@ -228,13 +294,13 @@ inline int bgc_complex_invert_fp32(const BgcComplexFP32* number, BgcComplexFP32*
|
|||
|
||||
const float multiplicand = 1.0f / square_modulus;
|
||||
|
||||
inverted->real = number->real * multiplicand;
|
||||
inverted->imaginary = -number->imaginary * multiplicand;
|
||||
inverse->real = number->real * multiplicand;
|
||||
inverse->imaginary = -number->imaginary * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_invert_fp64(const BgcComplexFP64* number, BgcComplexFP64* inverted)
|
||||
inline int bgc_complex_get_inverse_fp64(const BgcComplexFP64* number, BgcComplexFP64* inverse)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(number);
|
||||
|
||||
|
|
@ -244,70 +310,20 @@ inline int bgc_complex_invert_fp64(const BgcComplexFP64* number, BgcComplexFP64*
|
|||
|
||||
const double multiplicand = 1.0 / square_modulus;
|
||||
|
||||
inverted->real = number->real * multiplicand;
|
||||
inverted->imaginary = -number->imaginary * multiplicand;
|
||||
inverse->real = number->real * multiplicand;
|
||||
inverse->imaginary = -number->imaginary * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================ Get Product ================= //
|
||||
|
||||
inline void bgc_complex_get_product_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* result)
|
||||
inline int bgc_complex_invert_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
const float real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const float imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
result->real = real;
|
||||
result->imaginary = imaginary;
|
||||
return bgc_complex_get_inverse_fp32(number, number);
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_product_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* result)
|
||||
inline int bgc_complex_invert_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
const double real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const double imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
result->real = real;
|
||||
result->imaginary = imaginary;
|
||||
}
|
||||
|
||||
// ================= Get Ratio ================== //
|
||||
|
||||
inline int bgc_complex_get_ratio_fp32(const BgcComplexFP32* divident, const BgcComplexFP32* divisor, BgcComplexFP32* quotient)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const float imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const float multiplier = 1.0f / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_get_ratio_fp64(const BgcComplexFP64* divident, const BgcComplexFP64* divisor, BgcComplexFP64* quotient)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const double imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const double multiplier = 1.0 / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
return bgc_complex_get_inverse_fp64(number, number);
|
||||
}
|
||||
|
||||
// =============== Get Exponation =============== //
|
||||
|
|
@ -358,29 +374,35 @@ inline void bgc_complex_subtract_fp64(const BgcComplexFP64* minuend, const BgcCo
|
|||
difference->imaginary = minuend->imaginary - subtrahend->imaginary;
|
||||
}
|
||||
|
||||
// ============== Subtract scaled =============== //
|
||||
|
||||
inline void bgc_complex_subtract_scaled_fp32(const BgcComplexFP32* basic_number, const BgcComplexFP32* scalable_number, const float scale, BgcComplexFP32* difference)
|
||||
{
|
||||
difference->real = basic_number->real - scalable_number->real * scale;
|
||||
difference->imaginary = basic_number->imaginary - scalable_number->imaginary * scale;
|
||||
}
|
||||
|
||||
inline void bgc_complex_subtract_scaled_fp64(const BgcComplexFP64* basic_number, const BgcComplexFP64* scalable_number, const double scale, BgcComplexFP64* difference)
|
||||
{
|
||||
difference->real = basic_number->real - scalable_number->real * scale;
|
||||
difference->imaginary = basic_number->imaginary - scalable_number->imaginary * scale;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_complex_multiply_fp32(const BgcComplexFP32* multiplicand, const float multiplier, BgcComplexFP32* product)
|
||||
inline void bgc_complex_multiply_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* product)
|
||||
{
|
||||
const float real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const float imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
product->real = real;
|
||||
product->imaginary = imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_multiply_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* product)
|
||||
{
|
||||
const double real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const double imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
product->real = real;
|
||||
product->imaginary = imaginary;
|
||||
}
|
||||
|
||||
// ============= Multiply By Number ============= //
|
||||
|
||||
inline void bgc_complex_multiply_by_number_fp32(const BgcComplexFP32* multiplicand, const float multiplier, BgcComplexFP32* product)
|
||||
{
|
||||
product->real = multiplicand->real * multiplier;
|
||||
product->imaginary = multiplicand->imaginary * multiplier;
|
||||
}
|
||||
|
||||
inline void bgc_complex_multiply_fp64(const BgcComplexFP64* multiplicand, const double multiplier, BgcComplexFP64* product)
|
||||
inline void bgc_complex_multiply_by_number_fp64(const BgcComplexFP64* multiplicand, const double multiplier, BgcComplexFP64* product)
|
||||
{
|
||||
product->real = multiplicand->real * multiplier;
|
||||
product->imaginary = multiplicand->imaginary * multiplier;
|
||||
|
|
@ -388,14 +410,54 @@ inline void bgc_complex_multiply_fp64(const BgcComplexFP64* multiplicand, const
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_complex_divide_fp32(const BgcComplexFP32* dividend, const float divisor, BgcComplexFP32* quotient)
|
||||
inline int bgc_complex_devide_fp32(const BgcComplexFP32* divident, const BgcComplexFP32* divisor, BgcComplexFP32* quotient)
|
||||
{
|
||||
bgc_complex_multiply_fp32(dividend, 1.0f / divisor, quotient);
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const float imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const float multiplier = 1.0f / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline void bgc_complex_divide_fp64(const BgcComplexFP64* dividend, const double divisor, BgcComplexFP64* quotient)
|
||||
inline int bgc_complex_devide_fp64(const BgcComplexFP64* divident, const BgcComplexFP64* divisor, BgcComplexFP64* quotient)
|
||||
{
|
||||
bgc_complex_multiply_fp64(dividend, 1.0 / divisor, quotient);
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const double imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const double multiplier = 1.0 / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ============== Divide By Number ============== //
|
||||
|
||||
inline void bgc_complex_divide_by_number_fp32(const BgcComplexFP32* dividend, const float divisor, BgcComplexFP32* quotient)
|
||||
{
|
||||
bgc_complex_multiply_by_number_fp32(dividend, 1.0f / divisor, quotient);
|
||||
}
|
||||
|
||||
inline void bgc_complex_divide_by_number_fp64(const BgcComplexFP64* dividend, const double divisor, BgcComplexFP64* quotient)
|
||||
{
|
||||
bgc_complex_multiply_by_number_fp64(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ================== Average2 ================== //
|
||||
|
|
@ -428,7 +490,7 @@ inline void bgc_complex_get_mean_of_three_fp64(const BgcComplexFP64* number1, co
|
|||
|
||||
// =================== Linear =================== //
|
||||
|
||||
inline void bgc_complex_interpolate_linearly_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation)
|
||||
inline void bgc_complex_interpolate_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation)
|
||||
{
|
||||
const float counterphase = 1.0f - phase;
|
||||
|
||||
|
|
@ -436,7 +498,7 @@ inline void bgc_complex_interpolate_linearly_fp32(const BgcComplexFP32* number1,
|
|||
interpolation->imaginary = number1->imaginary * counterphase + number2->imaginary * phase;
|
||||
}
|
||||
|
||||
inline void bgc_complex_interpolate_linearly_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const double phase, BgcComplexFP64* interpolation)
|
||||
inline void bgc_complex_interpolate_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const double phase, BgcComplexFP64* interpolation)
|
||||
{
|
||||
const double counterphase = 1.0 - phase;
|
||||
|
||||
|
|
@ -444,54 +506,6 @@ inline void bgc_complex_interpolate_linearly_fp64(const BgcComplexFP64* number1,
|
|||
interpolation->imaginary = number1->imaginary * counterphase + number2->imaginary * phase;
|
||||
}
|
||||
|
||||
// ================== Minimal =================== //
|
||||
|
||||
inline void bgc_complex_minimize_fp32(const BgcComplexFP32* number, BgcComplexFP32* minimal)
|
||||
{
|
||||
if (number->real < minimal->real) {
|
||||
minimal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary < minimal->imaginary) {
|
||||
minimal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_complex_minimize_fp64(const BgcComplexFP64* number, BgcComplexFP64* minimal)
|
||||
{
|
||||
if (number->real < minimal->real) {
|
||||
minimal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary < minimal->imaginary) {
|
||||
minimal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
// ================== Maximal =================== //
|
||||
|
||||
inline void bgc_complex_maximize_fp32(const BgcComplexFP32* number, BgcComplexFP32* maximal)
|
||||
{
|
||||
if (number->real > maximal->real) {
|
||||
maximal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary > maximal->imaginary) {
|
||||
maximal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_complex_maximize_fp64(const BgcComplexFP64* number, BgcComplexFP64* maximal)
|
||||
{
|
||||
if (number->real > maximal->real) {
|
||||
maximal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary > maximal->imaginary) {
|
||||
maximal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
||||
inline int bgc_complex_are_close_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2)
|
||||
|
|
@ -525,7 +539,7 @@ inline int bgc_complex_are_close_fp64(const BgcComplexFP64* number1, const BgcCo
|
|||
return square_distance <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
|
||||
return square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus2;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -25,8 +25,17 @@ extern inline void bgc_cotes_number_swap_fp64(BgcCotesNumberFP64* number1, BgcCo
|
|||
extern inline void bgc_cotes_number_convert_fp64_to_fp32(const BgcCotesNumberFP64* source, BgcCotesNumberFP32* destination);
|
||||
extern inline void bgc_cotes_number_convert_fp32_to_fp64(const BgcCotesNumberFP32* source, BgcCotesNumberFP64* destination);
|
||||
|
||||
extern inline void bgc_cotes_number_invert_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* inverted);
|
||||
extern inline void bgc_cotes_number_invert_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* inverted);
|
||||
extern inline void bgc_cotes_number_make_opposite_fp32(BgcCotesNumberFP32* number);
|
||||
extern inline void bgc_cotes_number_make_opposite_fp64(BgcCotesNumberFP64* number);
|
||||
|
||||
extern inline void bgc_cotes_number_get_opposite_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* opposite);
|
||||
extern inline void bgc_cotes_number_get_opposite_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* opposite);
|
||||
|
||||
extern inline void bgc_cotes_number_invert_fp32(BgcCotesNumberFP32* number);
|
||||
extern inline void bgc_cotes_number_invert_fp64(BgcCotesNumberFP64* number);
|
||||
|
||||
extern inline void bgc_cotes_number_get_inverse_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* inverse);
|
||||
extern inline void bgc_cotes_number_get_inverse_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* inverse);
|
||||
|
||||
extern inline void bgc_cotes_number_get_exponation_fp32(const BgcCotesNumberFP32* base, const float exponent, BgcCotesNumberFP32* power);
|
||||
extern inline void bgc_cotes_number_get_exponation_fp64(const BgcCotesNumberFP64* base, const double exponent, BgcCotesNumberFP64* power);
|
||||
|
|
@ -52,34 +61,34 @@ extern inline void bgc_cotes_number_turn_vector_back_fp64(const BgcCotesNumberFP
|
|||
extern inline int bgc_cotes_number_are_close_fp32(const BgcCotesNumberFP32* number1, const BgcCotesNumberFP32* number2);
|
||||
extern inline int bgc_cotes_number_are_close_fp64(const BgcCotesNumberFP64* number1, const BgcCotesNumberFP64* number2);
|
||||
|
||||
void _bgc_cotes_number_normalize_fp32(const float square_modulus, _BgcTwinCotesNumberFP32* twin)
|
||||
void _bgc_cotes_number_normalize_fp32(const float square_modulus, BgcCotesNumberFP32* number)
|
||||
{
|
||||
// (square_modulus != square_modulus) is true when square_modulus is NaN
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
twin->cos = 1.0f;
|
||||
twin->sin = 0.0f;
|
||||
number->_cos = 1.0f;
|
||||
number->_sin = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
||||
twin->cos *= multiplier;
|
||||
twin->sin *= multiplier;
|
||||
number->_cos *= multiplier;
|
||||
number->_sin *= multiplier;
|
||||
}
|
||||
|
||||
void _bgc_cotes_number_normalize_fp64(const double square_modulus, _BgcTwinCotesNumberFP64* twin)
|
||||
void _bgc_cotes_number_normalize_fp64(const double square_modulus, BgcCotesNumberFP64* number)
|
||||
{
|
||||
// (square_modulus != square_modulus) is true when square_modulus is NaN
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
twin->cos = 1.0;
|
||||
twin->sin = 0.0;
|
||||
number->_cos = 1.0;
|
||||
number->_sin = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
||||
twin->cos *= multiplier;
|
||||
twin->sin *= multiplier;
|
||||
number->_cos *= multiplier;
|
||||
number->_sin *= multiplier;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,24 +12,14 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
const float cos, sin;
|
||||
float _cos, _sin;
|
||||
} BgcCotesNumberFP32;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const double cos, sin;
|
||||
double _cos, _sin;
|
||||
} BgcCotesNumberFP64;
|
||||
|
||||
// ================= Dark Twins ================= //
|
||||
|
||||
typedef struct {
|
||||
float cos, sin;
|
||||
} _BgcTwinCotesNumberFP32;
|
||||
|
||||
typedef struct {
|
||||
double cos, sin;
|
||||
} _BgcTwinCotesNumberFP64;
|
||||
|
||||
// ================= Constants ================== //
|
||||
|
||||
extern const BgcCotesNumberFP32 BGC_IDLE_COTES_NUMBER_FP32;
|
||||
|
|
@ -39,37 +29,31 @@ extern const BgcCotesNumberFP64 BGC_IDLE_COTES_NUMBER_FP64;
|
|||
|
||||
inline void bgc_cotes_number_reset_fp32(BgcCotesNumberFP32* number)
|
||||
{
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)number;
|
||||
|
||||
twin->cos = 1.0f;
|
||||
twin->sin = 0.0f;
|
||||
number->_cos = 1.0f;
|
||||
number->_sin = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_reset_fp64(BgcCotesNumberFP64* number)
|
||||
{
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)number;
|
||||
|
||||
twin->cos = 1.0;
|
||||
twin->sin = 0.0;
|
||||
number->_cos = 1.0;
|
||||
number->_sin = 0.0;
|
||||
}
|
||||
|
||||
// ==================== Set ===================== //
|
||||
|
||||
void _bgc_cotes_number_normalize_fp32(const float square_modulus, _BgcTwinCotesNumberFP32* twin);
|
||||
void _bgc_cotes_number_normalize_fp32(const float square_modulus, BgcCotesNumberFP32* twin);
|
||||
|
||||
void _bgc_cotes_number_normalize_fp64(const double square_modulus, _BgcTwinCotesNumberFP64* twin);
|
||||
void _bgc_cotes_number_normalize_fp64(const double square_modulus, BgcCotesNumberFP64* twin);
|
||||
|
||||
inline void bgc_cotes_number_set_values_fp32(const float x1, const float x2, BgcCotesNumberFP32* number)
|
||||
{
|
||||
const float square_modulus = x1 * x1 + x2 * x2;
|
||||
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)number;
|
||||
|
||||
twin->cos = x1;
|
||||
twin->sin = x2;
|
||||
number->_cos = x1;
|
||||
number->_sin = x2;
|
||||
|
||||
if (!bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
_bgc_cotes_number_normalize_fp32(square_modulus, twin);
|
||||
_bgc_cotes_number_normalize_fp32(square_modulus, number);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,13 +61,11 @@ inline void bgc_cotes_number_set_values_fp64(const double x1, const double x2, B
|
|||
{
|
||||
const double square_modulus = x1 * x1 + x2 * x2;
|
||||
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)number;
|
||||
|
||||
twin->cos = x1;
|
||||
twin->sin = x2;
|
||||
number->_cos = x1;
|
||||
number->_sin = x2;
|
||||
|
||||
if (!bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
_bgc_cotes_number_normalize_fp64(square_modulus, twin);
|
||||
_bgc_cotes_number_normalize_fp64(square_modulus, number);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,168 +75,148 @@ inline void bgc_cotes_number_set_turn_fp32(const float angle, const BgcAngleUnit
|
|||
{
|
||||
const float radians = bgc_angle_to_radians_fp32(angle, unit);
|
||||
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)number;
|
||||
|
||||
twin->cos = cosf(radians);
|
||||
twin->sin = sinf(radians);
|
||||
number->_cos = cosf(radians);
|
||||
number->_sin = sinf(radians);
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcCotesNumberFP64* number)
|
||||
{
|
||||
const double radians = bgc_angle_to_radians_fp64(angle, unit);
|
||||
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)number;
|
||||
|
||||
twin->cos = cos(radians);
|
||||
twin->sin = sin(radians);
|
||||
number->_cos = cos(radians);
|
||||
number->_sin = sin(radians);
|
||||
}
|
||||
|
||||
// =================== Angle =================== //
|
||||
|
||||
inline float bgc_cotes_number_get_angle_fp32(const BgcCotesNumberFP32* number, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (number->cos >= 1.0f - BGC_EPSYLON_FP32) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (number->cos <= -1.0f + BGC_EPSYLON_FP32) {
|
||||
return bgc_angle_get_half_circle_fp32(unit);
|
||||
}
|
||||
|
||||
if (number->sin >= 1.0f - BGC_EPSYLON_FP32) {
|
||||
return bgc_angle_get_quater_circle_fp32(unit);
|
||||
}
|
||||
|
||||
if (number->sin <= -1.0f + BGC_EPSYLON_FP32) {
|
||||
return 0.75f * bgc_angle_get_full_circle_fp32(unit);
|
||||
}
|
||||
|
||||
return bgc_radians_to_units_fp32(atan2f(number->sin, number->cos), unit);
|
||||
return bgc_radians_to_units_fp32(atan2f(number->_sin, number->_cos), unit);
|
||||
}
|
||||
|
||||
inline double bgc_cotes_number_get_angle_fp64(const BgcCotesNumberFP64* number, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (number->cos >= 1.0 - BGC_EPSYLON_FP64) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if (number->cos <= -1.0 + BGC_EPSYLON_FP64) {
|
||||
return bgc_angle_get_half_circle_fp64(unit);
|
||||
}
|
||||
|
||||
if (number->sin >= 1.0 - BGC_EPSYLON_FP64) {
|
||||
return bgc_angle_get_quater_circle_fp64(unit);
|
||||
}
|
||||
|
||||
if (number->sin <= -1.0 + BGC_EPSYLON_FP64) {
|
||||
return 0.75 * bgc_angle_get_full_circle_fp64(unit);
|
||||
}
|
||||
|
||||
return bgc_radians_to_units_fp64(atan2(number->sin, number->cos), unit);
|
||||
return bgc_radians_to_units_fp64(atan2(number->_sin, number->_cos), unit);
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_cotes_number_copy_fp32(const BgcCotesNumberFP32* source, BgcCotesNumberFP32* destination)
|
||||
{
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)destination;
|
||||
|
||||
twin->cos = source->cos;
|
||||
twin->sin = source->sin;
|
||||
destination->_cos = source->_cos;
|
||||
destination->_sin = source->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_copy_fp64(const BgcCotesNumberFP64* source, BgcCotesNumberFP64* destination)
|
||||
{
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)destination;
|
||||
|
||||
twin->cos = source->cos;
|
||||
twin->sin = source->sin;
|
||||
destination->_cos = source->_cos;
|
||||
destination->_sin = source->_sin;
|
||||
}
|
||||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void bgc_cotes_number_swap_fp32(BgcCotesNumberFP32* number1, BgcCotesNumberFP32* number2)
|
||||
{
|
||||
const float cos = number1->cos;
|
||||
const float sin = number1->sin;
|
||||
const float cos = number1->_cos;
|
||||
const float sin = number1->_sin;
|
||||
|
||||
_BgcTwinCotesNumberFP32* twin1 = (_BgcTwinCotesNumberFP32*)number1;
|
||||
number1->_cos = number2->_cos;
|
||||
number1->_sin = number2->_sin;
|
||||
|
||||
twin1->cos = number2->cos;
|
||||
twin1->sin = number2->sin;
|
||||
|
||||
_BgcTwinCotesNumberFP32* twin2 = (_BgcTwinCotesNumberFP32*)number2;
|
||||
|
||||
twin2->cos = cos;
|
||||
twin2->sin = sin;
|
||||
number2->_cos = cos;
|
||||
number2->_sin = sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_swap_fp64(BgcCotesNumberFP64* number1, BgcCotesNumberFP64* number2)
|
||||
{
|
||||
const double cos = number1->cos;
|
||||
const double sin = number1->sin;
|
||||
const double cos = number1->_cos;
|
||||
const double sin = number1->_sin;
|
||||
|
||||
_BgcTwinCotesNumberFP64* twin1 = (_BgcTwinCotesNumberFP64*)number1;
|
||||
number1->_cos = number2->_cos;
|
||||
number1->_sin = number2->_sin;
|
||||
|
||||
twin1->cos = number2->cos;
|
||||
twin1->sin = number2->sin;
|
||||
|
||||
_BgcTwinCotesNumberFP64* twin2 = (_BgcTwinCotesNumberFP64*)number2;
|
||||
|
||||
twin2->cos = cos;
|
||||
twin2->sin = sin;
|
||||
number2->_cos = cos;
|
||||
number2->_sin = sin;
|
||||
}
|
||||
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_cotes_number_convert_fp64_to_fp32(const BgcCotesNumberFP64* source, BgcCotesNumberFP32* destination)
|
||||
{
|
||||
bgc_cotes_number_set_values_fp32((float)source->cos, (float)source->sin, destination);
|
||||
bgc_cotes_number_set_values_fp32((float)source->_cos, (float)source->_sin, destination);
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_convert_fp32_to_fp64(const BgcCotesNumberFP32* source, BgcCotesNumberFP64* destination)
|
||||
{
|
||||
bgc_cotes_number_set_values_fp64((double)source->cos, (double)source->sin, destination);
|
||||
bgc_cotes_number_set_values_fp64((double)source->_cos, (double)source->_sin, destination);
|
||||
}
|
||||
|
||||
// ================== Negative ================== //
|
||||
|
||||
inline void bgc_cotes_number_make_opposite_fp32(BgcCotesNumberFP32* number)
|
||||
{
|
||||
number->_cos = -number->_cos;
|
||||
number->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_make_opposite_fp64(BgcCotesNumberFP64* number)
|
||||
{
|
||||
number->_cos = -number->_cos;
|
||||
number->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_get_opposite_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* opposite)
|
||||
{
|
||||
opposite->_cos = -number->_cos;
|
||||
opposite->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_get_opposite_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* opposite)
|
||||
{
|
||||
opposite->_cos = -number->_cos;
|
||||
opposite->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline void bgc_cotes_number_invert_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* inverted)
|
||||
inline void bgc_cotes_number_invert_fp32(BgcCotesNumberFP32* number)
|
||||
{
|
||||
_BgcTwinCotesNumberFP32* twin = (_BgcTwinCotesNumberFP32*)inverted;
|
||||
|
||||
twin->cos = number->cos;
|
||||
twin->sin = -number->sin;
|
||||
number->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
inline void bgc_cotes_number_invert_fp64(const BgcCotesNumberFP64* number, BgcCotesNumberFP64* inverted)
|
||||
inline void bgc_cotes_number_invert_fp64(BgcCotesNumberFP64* number)
|
||||
{
|
||||
_BgcTwinCotesNumberFP64* twin = (_BgcTwinCotesNumberFP64*)inverted;
|
||||
number->_sin = -number->_sin;
|
||||
}
|
||||
|
||||
twin->cos = number->cos;
|
||||
twin->sin = -number->sin;
|
||||
inline void bgc_cotes_number_get_inverse_fp32(const BgcCotesNumberFP32* number, BgcCotesNumberFP32* inverse)
|
||||
{
|
||||