Добавление проверки при делении, стандартизация возвращаемого значения (BGC_SUCCESS, BGC_FAILURE)
This commit is contained in:
parent
a4b9f8b2b9
commit
e9558ff977
27 changed files with 589 additions and 370 deletions
|
|
@ -92,52 +92,52 @@ inline void bgc_fp64_affine2_convert_to_fp32(BGC_FP32_Affine2* destination, cons
|
|||
|
||||
inline int bgc_fp32_affine2_invert(BGC_FP32_Affine2 * affine)
|
||||
{
|
||||
if (!bgc_fp32_matrix2x2_invert(&affine->distortion)) {
|
||||
return 0;
|
||||
if (bgc_fp32_matrix2x2_invert(&affine->distortion) != BGC_SUCCESS) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_multiply_matrix2x2_by_vector2(&affine->shift, &affine->distortion, &affine->shift);
|
||||
bgc_fp32_vector2_revert(&affine->shift);
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_affine2_invert(BGC_FP64_Affine2 * affine)
|
||||
{
|
||||
if (!bgc_fp64_matrix2x2_invert(&affine->distortion)) {
|
||||
return 0;
|
||||
if (bgc_fp64_matrix2x2_invert(&affine->distortion) != BGC_SUCCESS) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_multiply_matrix2x2_by_vector2(&affine->shift, &affine->distortion, &affine->shift);
|
||||
bgc_fp64_vector2_revert(&affine->shift);
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================= Get Inverse ================= //
|
||||
|
||||
inline int bgc_fp32_affine2_get_inverse(BGC_FP32_Affine2* inverse, const BGC_FP32_Affine2 * affine)
|
||||
{
|
||||
if (!bgc_fp32_matrix2x2_get_inverse(&inverse->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
if (bgc_fp32_matrix2x2_get_inverse(&inverse->distortion, &affine->distortion) != BGC_SUCCESS) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_multiply_matrix2x2_by_vector2(&inverse->shift, &inverse->distortion, &affine->shift);
|
||||
bgc_fp32_vector2_revert(&inverse->shift);
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_affine2_get_inverse(BGC_FP64_Affine2* inverse, const BGC_FP64_Affine2 * affine)
|
||||
{
|
||||
if (!bgc_fp64_matrix2x2_get_inverse(&inverse->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
if (bgc_fp64_matrix2x2_get_inverse(&inverse->distortion, &affine->distortion) != BGC_SUCCESS) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_multiply_matrix2x2_by_vector2(&inverse->shift, &inverse->distortion, &affine->shift);
|
||||
bgc_fp64_vector2_revert(&inverse->shift);
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// =================== Combine =================== //
|
||||
|
|
|
|||
|
|
@ -91,52 +91,52 @@ inline void bgc_fp64_affine3_convert_to_fp32(BGC_FP32_Affine3* destination, cons
|
|||
|
||||
inline int bgc_fp32_affine3_invert(BGC_FP32_Affine3 * affine)
|
||||
{
|
||||
if (!bgc_fp32_matrix3x3_invert(&affine->distortion)) {
|
||||
return 0;
|
||||
if (bgc_fp32_matrix3x3_invert(&affine->distortion) != BGC_SUCCESS) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_multiply_matrix3x3_by_vector3(&affine->shift, &affine->distortion, &affine->shift);
|
||||
bgc_fp32_vector3_revert(&affine->shift);
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_affine3_invert(BGC_FP64_Affine3 * affine)
|
||||
{
|
||||
if (!bgc_fp64_matrix3x3_invert(&affine->distortion)) {
|
||||
return 0;
|
||||
if (bgc_fp64_matrix3x3_invert(&affine->distortion) != BGC_SUCCESS) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_multiply_matrix3x3_by_vector3(&affine->shift, &affine->distortion, &affine->shift);
|
||||
bgc_fp64_vector3_revert(&affine->shift);
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================= Get Inverse ================= //
|
||||
|
||||
inline int bgc_fp32_affine3_get_inverse(BGC_FP32_Affine3* destination, const BGC_FP32_Affine3 * source)
|
||||
{
|
||||
if (!bgc_fp32_matrix3x3_get_inverse(&destination->distortion, &source->distortion)) {
|
||||
return 0;
|
||||
if (bgc_fp32_matrix3x3_get_inverse(&destination->distortion, &source->distortion) != BGC_SUCCESS) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_multiply_matrix3x3_by_vector3(&destination->shift, &destination->distortion, &source->shift);
|
||||
bgc_fp32_vector3_revert(&destination->shift);
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_affine3_get_inverse(BGC_FP64_Affine3* destination, const BGC_FP64_Affine3 * source)
|
||||
{
|
||||
if (!bgc_fp64_matrix3x3_get_inverse(&destination->distortion, &source->distortion)) {
|
||||
return 0;
|
||||
if (bgc_fp64_matrix3x3_get_inverse(&destination->distortion, &source->distortion) != BGC_SUCCESS) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_multiply_matrix3x3_by_vector3(&destination->shift, &destination->distortion, &source->shift);
|
||||
bgc_fp64_vector3_revert(&destination->shift);
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// =================== Combine =================== //
|
||||
|
|
|
|||
|
|
@ -51,12 +51,6 @@ extern inline int bgc_fp64_complex_invert(BGC_FP64_Complex* number);
|
|||
extern inline int bgc_fp32_complex_get_inverse(BGC_FP32_Complex* inverse, const BGC_FP32_Complex* number);
|
||||
extern inline int bgc_fp64_complex_get_inverse(BGC_FP64_Complex* inverse, const BGC_FP64_Complex* number);
|
||||
|
||||
extern inline void bgc_fp32_complex_get_product(BGC_FP32_Complex* product, const BGC_FP32_Complex* number1, const BGC_FP32_Complex* number2);
|
||||
extern inline void bgc_fp64_complex_get_product(BGC_FP64_Complex* product, const BGC_FP64_Complex* number1, const BGC_FP64_Complex* number2);
|
||||
|
||||
extern inline int bgc_fp32_complex_get_ratio(BGC_FP32_Complex* quotient, const BGC_FP32_Complex* divident, const BGC_FP32_Complex* divisor);
|
||||
extern inline int bgc_fp64_complex_get_ratio(BGC_FP64_Complex* quotient, const BGC_FP64_Complex* divident, const BGC_FP64_Complex* divisor);
|
||||
|
||||
extern inline void bgc_fp32_complex_add(BGC_FP32_Complex* sum, const BGC_FP32_Complex* number1, const BGC_FP32_Complex* number2);
|
||||
extern inline void bgc_fp64_complex_add(BGC_FP64_Complex* sum, const BGC_FP64_Complex* number1, const BGC_FP64_Complex* number2);
|
||||
|
||||
|
|
@ -66,11 +60,23 @@ extern inline void bgc_fp64_complex_add_scaled(BGC_FP64_Complex* sum, const BGC_
|
|||
extern inline void bgc_fp32_complex_subtract(BGC_FP32_Complex* difference, const BGC_FP32_Complex* minuend, const BGC_FP32_Complex* subtrahend);
|
||||
extern inline void bgc_fp64_complex_subtract(BGC_FP64_Complex* difference, const BGC_FP64_Complex* minuend, const BGC_FP64_Complex* subtrahend);
|
||||
|
||||
extern inline void bgc_fp32_complex_multiply(BGC_FP32_Complex* product, const BGC_FP32_Complex* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_complex_multiply(BGC_FP64_Complex* product, const BGC_FP64_Complex* multiplicand, const double multiplier);
|
||||
extern inline void bgc_fp32_complex_multiply_by_real(BGC_FP32_Complex* product, const BGC_FP32_Complex* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_complex_multiply_by_real(BGC_FP64_Complex* product, const BGC_FP64_Complex* multiplicand, const double multiplier);
|
||||
|
||||
extern inline void bgc_fp32_complex_divide(BGC_FP32_Complex* quotient, const BGC_FP32_Complex* dividend, const float divisor);
|
||||
extern inline void bgc_fp64_complex_divide(BGC_FP64_Complex* quotient, const BGC_FP64_Complex* dividend, const double divisor);
|
||||
extern inline void bgc_fp32_complex_multiply_by_complex(BGC_FP32_Complex* product, const BGC_FP32_Complex* multiplicand, const BGC_FP32_Complex* multiplier);
|
||||
extern inline void bgc_fp64_complex_multiply_by_complex(BGC_FP64_Complex* product, const BGC_FP64_Complex* multiplicand, const BGC_FP64_Complex* multiplier);
|
||||
|
||||
extern inline void bgc_fp32_complex_multiply_by_conjugate(BGC_FP32_Complex* product, const BGC_FP32_Complex* multiplicand, const BGC_FP32_Complex* multiplier_to_conjugate);
|
||||
extern inline void bgc_fp64_complex_multiply_by_conjugate(BGC_FP64_Complex* product, const BGC_FP64_Complex* multiplicand, const BGC_FP64_Complex* multiplier_to_conjugate);
|
||||
|
||||
extern inline void bgc_fp32_complex_divide_by_real(BGC_FP32_Complex* quotient, const BGC_FP32_Complex* dividend, const float divisor);
|
||||
extern inline void bgc_fp64_complex_divide_by_real(BGC_FP64_Complex* quotient, const BGC_FP64_Complex* dividend, const double divisor);
|
||||
|
||||
extern inline int bgc_fp32_complex_divide_by_complex(BGC_FP32_Complex* quotient, const BGC_FP32_Complex* divident, const BGC_FP32_Complex* divisor);
|
||||
extern inline int bgc_fp64_complex_divide_by_complex(BGC_FP64_Complex* quotient, const BGC_FP64_Complex* divident, const BGC_FP64_Complex* divisor);
|
||||
|
||||
extern inline int bgc_fp32_complex_divide_by_conjugate(BGC_FP32_Complex* quotient, const BGC_FP32_Complex* divident, const BGC_FP32_Complex* divisor_to_conjugate);
|
||||
extern inline int bgc_fp64_complex_divide_by_conjugate(BGC_FP64_Complex* quotient, const BGC_FP64_Complex* divident, const BGC_FP64_Complex* divisor_to_conjugate);
|
||||
|
||||
extern inline void bgc_fp32_complex_get_mean2(BGC_FP32_Complex* mean, const BGC_FP32_Complex* number1, const BGC_FP32_Complex* number2);
|
||||
extern inline void bgc_fp64_complex_get_mean2(BGC_FP64_Complex* mean, const BGC_FP64_Complex* number1, const BGC_FP64_Complex* number2);
|
||||
|
|
|
|||
|
|
@ -174,12 +174,12 @@ inline int bgc_fp32_complex_normalize(BGC_FP32_Complex* number)
|
|||
{
|
||||
const float square_modulus = bgc_fp32_complex_get_square_modulus(number);
|
||||
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
return 1;
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return 0;
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
const float multiplicand = sqrtf(1.0f / square_modulus);
|
||||
|
|
@ -187,19 +187,19 @@ inline int bgc_fp32_complex_normalize(BGC_FP32_Complex* number)
|
|||
number->real *= multiplicand;
|
||||
number->imaginary *= multiplicand;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_complex_normalize(BGC_FP64_Complex* number)
|
||||
{
|
||||
const double square_modulus = bgc_fp64_complex_get_square_modulus(number);
|
||||
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
return 1;
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return 0;
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
const double multiplicand = sqrt(1.0 / square_modulus);
|
||||
|
|
@ -207,23 +207,23 @@ inline int bgc_fp64_complex_normalize(BGC_FP64_Complex* number)
|
|||
number->real *= multiplicand;
|
||||
number->imaginary *= multiplicand;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp32_complex_get_normalized(BGC_FP32_Complex* normalized, const BGC_FP32_Complex* number)
|
||||
{
|
||||
const float square_modulus = bgc_fp32_complex_get_square_modulus(number);
|
||||
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
normalized->real = number->real;
|
||||
normalized->imaginary = number->imaginary;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
normalized->real = 0.0f;
|
||||
normalized->imaginary = 0.0f;
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
normalized->real = number->real;
|
||||
normalized->imaginary = number->imaginary;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
const float multiplicand = sqrtf(1.0f / square_modulus);
|
||||
|
|
@ -231,23 +231,23 @@ inline int bgc_fp32_complex_get_normalized(BGC_FP32_Complex* normalized, const B
|
|||
normalized->real = number->real * multiplicand;
|
||||
normalized->imaginary = number->imaginary * multiplicand;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_complex_get_normalized(BGC_FP64_Complex* normalized, const BGC_FP64_Complex* number)
|
||||
{
|
||||
const double square_modulus = bgc_fp64_complex_get_square_modulus(number);
|
||||
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
normalized->real = number->real;
|
||||
normalized->imaginary = number->imaginary;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
normalized->real = 0.0;
|
||||
normalized->imaginary = 0.0;
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
normalized->real = number->real;
|
||||
normalized->imaginary = number->imaginary;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
const double multiplicand = sqrt(1.0 / square_modulus);
|
||||
|
|
@ -255,7 +255,7 @@ inline int bgc_fp64_complex_get_normalized(BGC_FP64_Complex* normalized, const B
|
|||
normalized->real = number->real * multiplicand;
|
||||
normalized->imaginary = number->imaginary * multiplicand;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================= Conjugate ================== //
|
||||
|
|
@ -289,7 +289,7 @@ inline int bgc_fp32_complex_get_inverse(BGC_FP32_Complex* inverse, const BGC_FP3
|
|||
const float square_modulus = bgc_fp32_complex_get_square_modulus(number);
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float multiplicand = 1.0f / square_modulus;
|
||||
|
|
@ -297,7 +297,7 @@ inline int bgc_fp32_complex_get_inverse(BGC_FP32_Complex* inverse, const BGC_FP3
|
|||
inverse->real = number->real * multiplicand;
|
||||
inverse->imaginary = -number->imaginary * multiplicand;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_complex_get_inverse(BGC_FP64_Complex* inverse, const BGC_FP64_Complex* number)
|
||||
|
|
@ -305,7 +305,7 @@ inline int bgc_fp64_complex_get_inverse(BGC_FP64_Complex* inverse, const BGC_FP6
|
|||
const double square_modulus = bgc_fp64_complex_get_square_modulus(number);
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double multiplicand = 1.0 / square_modulus;
|
||||
|
|
@ -313,7 +313,7 @@ inline int bgc_fp64_complex_get_inverse(BGC_FP64_Complex* inverse, const BGC_FP6
|
|||
inverse->real = number->real * multiplicand;
|
||||
inverse->imaginary = -number->imaginary * multiplicand;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp32_complex_invert(BGC_FP32_Complex* number)
|
||||
|
|
@ -374,90 +374,142 @@ inline void bgc_fp64_complex_subtract(BGC_FP64_Complex* difference, const BGC_FP
|
|||
difference->imaginary = minuend->imaginary - subtrahend->imaginary;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
// ========== Multiply By Real Number =========== //
|
||||
|
||||
inline void bgc_fp32_complex_get_product(BGC_FP32_Complex* product, const BGC_FP32_Complex* number1, const BGC_FP32_Complex* number2)
|
||||
{
|
||||
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_fp64_complex_get_product(BGC_FP64_Complex* product, const BGC_FP64_Complex* number1, const BGC_FP64_Complex* number2)
|
||||
{
|
||||
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_fp32_complex_multiply(BGC_FP32_Complex* product, const BGC_FP32_Complex* multiplicand, const float multiplier)
|
||||
inline void bgc_fp32_complex_multiply_by_real(BGC_FP32_Complex* product, const BGC_FP32_Complex* multiplicand, const float multiplier)
|
||||
{
|
||||
product->real = multiplicand->real * multiplier;
|
||||
product->imaginary = multiplicand->imaginary * multiplier;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_complex_multiply(BGC_FP64_Complex* product, const BGC_FP64_Complex* multiplicand, const double multiplier)
|
||||
inline void bgc_fp64_complex_multiply_by_real(BGC_FP64_Complex* product, const BGC_FP64_Complex* multiplicand, const double multiplier)
|
||||
{
|
||||
product->real = multiplicand->real * multiplier;
|
||||
product->imaginary = multiplicand->imaginary * multiplier;
|
||||
}
|
||||
|
||||
// =================== Divide =================== //
|
||||
// ========= Multiply By Complex Number ========= //
|
||||
|
||||
inline int bgc_fp32_complex_get_ratio(BGC_FP32_Complex* quotient, const BGC_FP32_Complex* divident, const BGC_FP32_Complex* divisor)
|
||||
inline void bgc_fp32_complex_multiply_by_complex(BGC_FP32_Complex* product, const BGC_FP32_Complex* multiplicand, const BGC_FP32_Complex* multiplier)
|
||||
{
|
||||
const float real = multiplicand->real * multiplier->real - multiplicand->imaginary * multiplier->imaginary;
|
||||
const float imaginary = multiplicand->real * multiplier->imaginary + multiplicand->imaginary * multiplier->real;
|
||||
|
||||
product->real = real;
|
||||
product->imaginary = imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_complex_multiply_by_complex(BGC_FP64_Complex* product, const BGC_FP64_Complex* multiplicand, const BGC_FP64_Complex* multiplier)
|
||||
{
|
||||
const double real = multiplicand->real * multiplier->real - multiplicand->imaginary * multiplier->imaginary;
|
||||
const double imaginary = multiplicand->real * multiplier->imaginary + multiplicand->imaginary * multiplier->real;
|
||||
|
||||
product->real = real;
|
||||
product->imaginary = imaginary;
|
||||
}
|
||||
|
||||
// ======== Multiply By Conjugate Number ======== //
|
||||
|
||||
inline void bgc_fp32_complex_multiply_by_conjugate(BGC_FP32_Complex* product, const BGC_FP32_Complex* multiplicand, const BGC_FP32_Complex* multiplier_to_conjugate)
|
||||
{
|
||||
const float real = multiplicand->real * multiplier_to_conjugate->real + multiplicand->imaginary * multiplier_to_conjugate->imaginary;
|
||||
const float imaginary = multiplicand->imaginary * multiplier_to_conjugate->real - multiplicand->real * multiplier_to_conjugate->imaginary;
|
||||
|
||||
product->real = real;
|
||||
product->imaginary = imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_complex_multiply_by_conjugate(BGC_FP64_Complex* product, const BGC_FP64_Complex* multiplicand, const BGC_FP64_Complex* multiplier_to_conjugate)
|
||||
{
|
||||
const double real = multiplicand->real * multiplier_to_conjugate->real + multiplicand->imaginary * multiplier_to_conjugate->imaginary;
|
||||
const double imaginary = multiplicand->imaginary * multiplier_to_conjugate->real - multiplicand->real * multiplier_to_conjugate->imaginary;
|
||||
|
||||
product->real = real;
|
||||
product->imaginary = imaginary;
|
||||
}
|
||||
|
||||
// =========== Divide by Real Number ============ //
|
||||
|
||||
inline int bgc_fp32_complex_divide_by_real(BGC_FP32_Complex* quotient, const BGC_FP32_Complex* dividend, const float divisor)
|
||||
{
|
||||
if (bgc_fp32_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_complex_multiply_by_real(quotient, dividend, 1.0f / divisor);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_complex_divide_by_real(BGC_FP64_Complex* quotient, const BGC_FP64_Complex* dividend, const double divisor)
|
||||
{
|
||||
if (bgc_fp64_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_complex_multiply_by_real(quotient, dividend, 1.0 / divisor);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ========== Divide by Complex Number ========== //
|
||||
|
||||
inline int bgc_fp32_complex_divide_by_complex(BGC_FP32_Complex* quotient, const BGC_FP32_Complex* divident, const BGC_FP32_Complex* divisor)
|
||||
{
|
||||
const float square_modulus = bgc_fp32_complex_get_square_modulus(divisor);
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON) {
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const float imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
bgc_fp32_complex_multiply_by_conjugate(quotient, divident, divisor);
|
||||
bgc_fp32_complex_multiply_by_real(quotient, quotient, 1.0f / square_modulus);
|
||||
|
||||
const float multiplier = 1.0f / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_complex_get_ratio(BGC_FP64_Complex* quotient, const BGC_FP64_Complex* divident, const BGC_FP64_Complex* divisor)
|
||||
inline int bgc_fp64_complex_divide_by_complex(BGC_FP64_Complex* quotient, const BGC_FP64_Complex* divident, const BGC_FP64_Complex* divisor)
|
||||
{
|
||||
const double square_modulus = bgc_fp64_complex_get_square_modulus(divisor);
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON) {
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const double imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
bgc_fp64_complex_multiply_by_conjugate(quotient, divident, divisor);
|
||||
bgc_fp64_complex_multiply_by_real(quotient, quotient, 1.0 / square_modulus);
|
||||
|
||||
const double multiplier = 1.0 / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ============== Divide By Number ============== //
|
||||
// ========= Divide By Conjugate Number ========= //
|
||||
|
||||
inline void bgc_fp32_complex_divide(BGC_FP32_Complex* quotient, const BGC_FP32_Complex* dividend, const float divisor)
|
||||
inline int bgc_fp32_complex_divide_by_conjugate(BGC_FP32_Complex* quotient, const BGC_FP32_Complex* divident, const BGC_FP32_Complex* divisor_to_conjugate)
|
||||
{
|
||||
bgc_fp32_complex_multiply(quotient, dividend, 1.0f / divisor);
|
||||
const float square_modulus = bgc_fp32_complex_get_square_modulus(divisor_to_conjugate);
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_complex_multiply_by_complex(quotient, divident, divisor_to_conjugate);
|
||||
bgc_fp32_complex_multiply_by_real(quotient, quotient, 1.0f / square_modulus);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_complex_divide(BGC_FP64_Complex* quotient, const BGC_FP64_Complex* dividend, const double divisor)
|
||||
inline int bgc_fp64_complex_divide_by_conjugate(BGC_FP64_Complex* quotient, const BGC_FP64_Complex* divident, const BGC_FP64_Complex* divisor_to_conjugate)
|
||||
{
|
||||
bgc_fp64_complex_multiply(quotient, dividend, 1.0 / divisor);
|
||||
const double square_modulus = bgc_fp64_complex_get_square_modulus(divisor_to_conjugate);
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_complex_multiply_by_complex(quotient, divident, divisor_to_conjugate);
|
||||
bgc_fp32_complex_multiply_by_real(quotient, quotient, 1.0 / square_modulus);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================== Average2 ================== //
|
||||
|
|
|
|||
|
|
@ -12,6 +12,18 @@ extern inline void bgc_fp64_dual_number_copy(BGC_FP64_DualNumber* destination, c
|
|||
extern inline void bgc_fp32_dual_number_swap(BGC_FP32_DualNumber* first, BGC_FP32_DualNumber* second);
|
||||
extern inline void bgc_fp64_dual_number_swap(BGC_FP64_DualNumber* first, BGC_FP64_DualNumber* second);
|
||||
|
||||
extern inline void bgc_fp32_dual_number_revert(BGC_FP32_DualNumber* number);
|
||||
extern inline void bgc_fp64_dual_number_revert(BGC_FP64_DualNumber* number);
|
||||
|
||||
extern inline void bgc_fp32_number_get_reverse(BGC_FP32_DualNumber* reverse, const BGC_FP32_DualNumber* number);
|
||||
extern inline void bgc_fp64_number_get_reverse(BGC_FP64_DualNumber* reverse, const BGC_FP64_DualNumber* number);
|
||||
|
||||
extern inline void bgc_fp32_dual_number_conjugate(BGC_FP32_DualNumber* number);
|
||||
extern inline void bgc_fp64_dual_number_conjugate(BGC_FP64_DualNumber* number);
|
||||
|
||||
extern inline void bgc_fp32_dual_number_get_conjugate(BGC_FP32_DualNumber* conjugate, const BGC_FP32_DualNumber* number);
|
||||
extern inline void bgc_fp64_dual_number_get_conjugate(BGC_FP64_DualNumber* conjugate, const BGC_FP64_DualNumber* number);
|
||||
|
||||
extern inline void bgc_fp32_dual_number_add(BGC_FP32_DualNumber* sum, const BGC_FP32_DualNumber* first, const BGC_FP32_DualNumber* second);
|
||||
extern inline void bgc_fp64_dual_number_add(BGC_FP64_DualNumber* sum, const BGC_FP64_DualNumber* first, const BGC_FP64_DualNumber* second);
|
||||
|
||||
|
|
@ -41,9 +53,3 @@ extern inline void bgc_fp64_dual_number_get_mean3(BGC_FP64_DualNumber* mean, con
|
|||
|
||||
extern inline void bgc_fp32_dual_number_interpolate(BGC_FP32_DualNumber* interpolation, const BGC_FP32_DualNumber* first, const BGC_FP32_DualNumber* second, const float phase);
|
||||
extern inline void bgc_fp64_dual_number_interpolate(BGC_FP64_DualNumber* interpolation, const BGC_FP64_DualNumber* first, const BGC_FP64_DualNumber* second, const double phase);
|
||||
|
||||
extern inline void bgc_fp32_dual_number_revert(BGC_FP32_DualNumber* number);
|
||||
extern inline void bgc_fp64_dual_number_revert(BGC_FP64_DualNumber* number);
|
||||
|
||||
extern inline void bgc_fp32_number_get_reverse(BGC_FP32_DualNumber* reverse, const BGC_FP32_DualNumber* number);
|
||||
extern inline void bgc_fp64_number_get_reverse(BGC_FP64_DualNumber* reverse, const BGC_FP64_DualNumber* number);
|
||||
|
|
|
|||
|
|
@ -69,6 +69,74 @@ inline void bgc_fp64_dual_number_swap(BGC_FP64_DualNumber* first, BGC_FP64_DualN
|
|||
first->dual = second->dual;
|
||||
}
|
||||
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_fp64_dual_number_convert_to_fp32(BGC_FP32_DualNumber* first, BGC_FP64_DualNumber* second)
|
||||
{
|
||||
first->real = (float) second->real;
|
||||
first->dual = (float) second->dual;
|
||||
}
|
||||
|
||||
inline void bgc_fp32_dual_number_convert_to_fp64(BGC_FP64_DualNumber* first, BGC_FP32_DualNumber* second)
|
||||
{
|
||||
first->real = second->real;
|
||||
first->dual = second->dual;
|
||||
}
|
||||
|
||||
// =================== Revert =================== //
|
||||
|
||||
inline void bgc_fp32_dual_number_revert(BGC_FP32_DualNumber* number)
|
||||
{
|
||||
number->real = -number->real;
|
||||
number->dual = -number->dual;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_dual_number_revert(BGC_FP64_DualNumber* number)
|
||||
{
|
||||
number->real = -number->real;
|
||||
number->dual = -number->dual;
|
||||
}
|
||||
|
||||
// ================ Get Reverse ================= //
|
||||
|
||||
inline void bgc_fp32_number_get_reverse(BGC_FP32_DualNumber* reverse, const BGC_FP32_DualNumber* number)
|
||||
{
|
||||
reverse->real = -number->real;
|
||||
reverse->dual = -number->dual;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_number_get_reverse(BGC_FP64_DualNumber* reverse, const BGC_FP64_DualNumber* number)
|
||||
{
|
||||
reverse->real = -number->real;
|
||||
reverse->dual = -number->dual;
|
||||
}
|
||||
|
||||
// ================= Conjugate ================== //
|
||||
|
||||
inline void bgc_fp32_dual_number_conjugate(BGC_FP32_DualNumber* number)
|
||||
{
|
||||
number->dual = -number->dual;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_dual_number_conjugate(BGC_FP64_DualNumber* number)
|
||||
{
|
||||
number->dual = -number->dual;
|
||||
}
|
||||
|
||||
// =============== Get Conjugate ================ //
|
||||
|
||||
inline void bgc_fp32_dual_number_get_conjugate(BGC_FP32_DualNumber* conjugate, const BGC_FP32_DualNumber* number)
|
||||
{
|
||||
conjugate->real = number->real;
|
||||
conjugate->dual = -number->dual;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_dual_number_get_conjugate(BGC_FP64_DualNumber* conjugate, const BGC_FP64_DualNumber* number)
|
||||
{
|
||||
conjugate->real = number->real;
|
||||
conjugate->dual = -number->dual;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
inline void bgc_fp32_dual_number_add(BGC_FP32_DualNumber* sum, const BGC_FP32_DualNumber* first, const BGC_FP32_DualNumber* second)
|
||||
|
|
@ -211,32 +279,4 @@ inline void bgc_fp64_dual_number_interpolate(BGC_FP64_DualNumber* interpolation,
|
|||
interpolation->dual = first->dual * counter_phase + second->dual * phase;
|
||||
}
|
||||
|
||||
// =================== Revert =================== //
|
||||
|
||||
inline void bgc_fp32_dual_number_revert(BGC_FP32_DualNumber* number)
|
||||
{
|
||||
number->real = -number->real;
|
||||
number->dual = -number->dual;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_dual_number_revert(BGC_FP64_DualNumber* number)
|
||||
{
|
||||
number->real = -number->real;
|
||||
number->dual = -number->dual;
|
||||
}
|
||||
|
||||
// ================ Get Reverse ================= //
|
||||
|
||||
inline void bgc_fp32_number_get_reverse(BGC_FP32_DualNumber* reverse, const BGC_FP32_DualNumber* number)
|
||||
{
|
||||
reverse->real = -number->real;
|
||||
reverse->dual = -number->dual;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_number_get_reverse(BGC_FP64_DualNumber* reverse, const BGC_FP64_DualNumber* number)
|
||||
{
|
||||
reverse->real = -number->real;
|
||||
reverse->dual = -number->dual;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ extern inline void bgc_fp64_dual_quaternion_add_scaled(BGC_FP64_DualQuaternion*
|
|||
extern inline void bgc_fp32_dual_quaternion_subtract(BGC_FP32_DualQuaternion* difference, const BGC_FP32_DualQuaternion* minuend, const BGC_FP32_DualQuaternion* subtrahend);
|
||||
extern inline void bgc_fp64_dual_quaternion_subtract(BGC_FP64_DualQuaternion* difference, const BGC_FP64_DualQuaternion* minuend, const BGC_FP64_DualQuaternion* subtrahend);
|
||||
|
||||
extern inline void bgc_fp32_dual_quaternion_multiply_by_number(BGC_FP32_DualQuaternion* product, const BGC_FP32_DualQuaternion* multiplicand, const float multipier);
|
||||
extern inline void bgc_fp64_dual_quaternion_multiply_by_number(BGC_FP64_DualQuaternion* product, const BGC_FP64_DualQuaternion* multiplicand, const double multipier);
|
||||
extern inline void bgc_fp32_dual_quaternion_multiply_by_real(BGC_FP32_DualQuaternion* product, const BGC_FP32_DualQuaternion* multiplicand, const float multipier);
|
||||
extern inline void bgc_fp64_dual_quaternion_multiply_by_real(BGC_FP64_DualQuaternion* product, const BGC_FP64_DualQuaternion* multiplicand, const double multipier);
|
||||
|
||||
extern inline void bgc_fp32_dual_quaternion_divide_by_number(BGC_FP32_DualQuaternion* quotient, const BGC_FP32_DualQuaternion* divident, const float divisor);
|
||||
extern inline void bgc_fp64_dual_quaternion_divide_by_number(BGC_FP64_DualQuaternion* quotient, const BGC_FP64_DualQuaternion* divident, const double divisor);
|
||||
extern inline void bgc_fp32_dual_quaternion_divide_by_real(BGC_FP32_DualQuaternion* quotient, const BGC_FP32_DualQuaternion* divident, const float divisor);
|
||||
extern inline void bgc_fp64_dual_quaternion_divide_by_real(BGC_FP64_DualQuaternion* quotient, const BGC_FP64_DualQuaternion* divident, const double divisor);
|
||||
|
||||
extern inline void bgc_fp32_dual_quaternion_get_mean2(BGC_FP32_DualQuaternion* mean, const BGC_FP32_DualQuaternion* quaternion1, const BGC_FP32_DualQuaternion* quaternion2);
|
||||
extern inline void bgc_fp64_dual_quaternion_get_mean2(BGC_FP64_DualQuaternion* mean, const BGC_FP64_DualQuaternion* quaternion1, const BGC_FP64_DualQuaternion* quaternion2);
|
||||
|
|
|
|||
|
|
@ -113,28 +113,28 @@ inline void bgc_fp64_dual_quaternion_subtract(BGC_FP64_DualQuaternion* differenc
|
|||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_fp32_dual_quaternion_multiply_by_number(BGC_FP32_DualQuaternion* product, const BGC_FP32_DualQuaternion* multiplicand, const float multipier)
|
||||
inline void bgc_fp32_dual_quaternion_multiply_by_real(BGC_FP32_DualQuaternion* product, const BGC_FP32_DualQuaternion* multiplicand, const float multipier)
|
||||
{
|
||||
bgc_fp32_quaternion_multiply_by_number(&product->real, &multiplicand->real, multipier);
|
||||
bgc_fp32_quaternion_multiply_by_number(&product->dual, &multiplicand->dual, multipier);
|
||||
bgc_fp32_quaternion_multiply_by_real(&product->real, &multiplicand->real, multipier);
|
||||
bgc_fp32_quaternion_multiply_by_real(&product->dual, &multiplicand->dual, multipier);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_dual_quaternion_multiply_by_number(BGC_FP64_DualQuaternion* product, const BGC_FP64_DualQuaternion* multiplicand, const double multipier)
|
||||
inline void bgc_fp64_dual_quaternion_multiply_by_real(BGC_FP64_DualQuaternion* product, const BGC_FP64_DualQuaternion* multiplicand, const double multipier)
|
||||
{
|
||||
bgc_fp64_quaternion_multiply_by_number(&product->real, &multiplicand->real, multipier);
|
||||
bgc_fp64_quaternion_multiply_by_number(&product->dual, &multiplicand->dual, multipier);
|
||||
bgc_fp64_quaternion_multiply_by_real(&product->real, &multiplicand->real, multipier);
|
||||
bgc_fp64_quaternion_multiply_by_real(&product->dual, &multiplicand->dual, multipier);
|
||||
}
|
||||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_fp32_dual_quaternion_divide_by_number(BGC_FP32_DualQuaternion* quotient, const BGC_FP32_DualQuaternion* divident, const float divisor)
|
||||
inline void bgc_fp32_dual_quaternion_divide_by_real(BGC_FP32_DualQuaternion* quotient, const BGC_FP32_DualQuaternion* divident, const float divisor)
|
||||
{
|
||||
bgc_fp32_dual_quaternion_multiply_by_number(quotient, divident, 1.0f / divisor);
|
||||
bgc_fp32_dual_quaternion_multiply_by_real(quotient, divident, 1.0f / divisor);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_dual_quaternion_divide_by_number(BGC_FP64_DualQuaternion* quotient, const BGC_FP64_DualQuaternion* divident, const double divisor)
|
||||
inline void bgc_fp64_dual_quaternion_divide_by_real(BGC_FP64_DualQuaternion* quotient, const BGC_FP64_DualQuaternion* divident, const double divisor)
|
||||
{
|
||||
bgc_fp64_dual_quaternion_multiply_by_number(quotient, divident, 1.0 / divisor);
|
||||
bgc_fp64_dual_quaternion_multiply_by_real(quotient, divident, 1.0 / divisor);
|
||||
}
|
||||
|
||||
// ================ Mean of Two ================= //
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@ extern inline void bgc_fp64_dual_vector3_add_scaled(BGC_FP64_DualVector3* sum, c
|
|||
extern inline void bgc_fp32_dual_vector3_subtract(BGC_FP32_DualVector3* difference, const BGC_FP32_DualVector3* minuend, const BGC_FP32_DualVector3* subtrahend);
|
||||
extern inline void bgc_fp64_dual_vector3_subtract(BGC_FP64_DualVector3* difference, const BGC_FP64_DualVector3* minuend, const BGC_FP64_DualVector3* subtrahend);
|
||||
|
||||
extern inline void bgc_fp32_dual_vector3_multiply(BGC_FP32_DualVector3* product, const BGC_FP32_DualVector3* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_dual_vector3_multiply(BGC_FP64_DualVector3* product, const BGC_FP64_DualVector3* multiplicand, const double multiplier);
|
||||
extern inline void bgc_fp32_dual_vector3_multiply_by_real(BGC_FP32_DualVector3* product, const BGC_FP32_DualVector3* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_dual_vector3_multiply_by_real(BGC_FP64_DualVector3* product, const BGC_FP64_DualVector3* multiplicand, const double multiplier);
|
||||
|
||||
extern inline void bgc_fp32_dual_vector3_divide(BGC_FP32_DualVector3* quotient, const BGC_FP32_DualVector3* dividend, const float divisor);
|
||||
extern inline void bgc_fp64_dual_vector3_divide(BGC_FP64_DualVector3* quotient, const BGC_FP64_DualVector3* dividend, const double divisor);
|
||||
extern inline int bgc_fp32_dual_vector3_divide_by_real(BGC_FP32_DualVector3* quotient, const BGC_FP32_DualVector3* dividend, const float divisor);
|
||||
extern inline int bgc_fp64_dual_vector3_divide_by_real(BGC_FP64_DualVector3* quotient, const BGC_FP64_DualVector3* dividend, const double divisor);
|
||||
|
||||
extern inline void bgc_fp32_dual_vector3_get_mean2(BGC_FP32_DualVector3* mean, const BGC_FP32_DualVector3* vector1, const BGC_FP32_DualVector3* vector2);
|
||||
extern inline void bgc_fp64_dual_vector3_get_mean2(BGC_FP64_DualVector3* mean, const BGC_FP64_DualVector3* vector1, const BGC_FP64_DualVector3* vector2);
|
||||
|
|
|
|||
|
|
@ -145,28 +145,46 @@ inline void bgc_fp64_dual_vector3_subtract(BGC_FP64_DualVector3* difference, con
|
|||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_fp32_dual_vector3_multiply(BGC_FP32_DualVector3* product, const BGC_FP32_DualVector3* multiplicand, const float multiplier)
|
||||
inline void bgc_fp32_dual_vector3_multiply_by_real(BGC_FP32_DualVector3* product, const BGC_FP32_DualVector3* multiplicand, const float multiplier)
|
||||
{
|
||||
bgc_fp32_vector3_multiply(&product->real, &multiplicand->real, multiplier);
|
||||
bgc_fp32_vector3_multiply(&product->dual, &multiplicand->dual, multiplier);
|
||||
bgc_fp32_vector3_multiply_by_real(&product->real, &multiplicand->real, multiplier);
|
||||
bgc_fp32_vector3_multiply_by_real(&product->dual, &multiplicand->dual, multiplier);
|
||||
}
|
||||
|
||||
inline void bgc_fp64_dual_vector3_multiply(BGC_FP64_DualVector3* product, const BGC_FP64_DualVector3* multiplicand, const double multiplier)
|
||||
inline void bgc_fp64_dual_vector3_multiply_by_real(BGC_FP64_DualVector3* product, const BGC_FP64_DualVector3* multiplicand, const double multiplier)
|
||||
{
|
||||
bgc_fp64_vector3_multiply(&product->real, &multiplicand->real, multiplier);
|
||||
bgc_fp64_vector3_multiply(&product->dual, &multiplicand->dual, multiplier);
|
||||
bgc_fp64_vector3_multiply_by_real(&product->real, &multiplicand->real, multiplier);
|
||||
bgc_fp64_vector3_multiply_by_real(&product->dual, &multiplicand->dual, multiplier);
|
||||
}
|
||||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_fp32_dual_vector3_divide(BGC_FP32_DualVector3* quotient, const BGC_FP32_DualVector3* dividend, const float divisor)
|
||||
inline int bgc_fp32_dual_vector3_divide_by_real(BGC_FP32_DualVector3* quotient, const BGC_FP32_DualVector3* dividend, const float divisor)
|
||||
{
|
||||
bgc_fp32_dual_vector3_multiply(quotient, dividend, 1.0f / divisor);
|
||||
if (bgc_fp32_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float multiplier = 1.0f / divisor;
|
||||
|
||||
bgc_fp32_vector3_multiply_by_real("ient->real, ÷nd->real, multiplier);
|
||||
bgc_fp32_vector3_multiply_by_real("ient->dual, ÷nd->dual, multiplier);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_dual_vector3_divide(BGC_FP64_DualVector3* quotient, const BGC_FP64_DualVector3* dividend, const double divisor)
|
||||
inline int bgc_fp64_dual_vector3_divide_by_real(BGC_FP64_DualVector3* quotient, const BGC_FP64_DualVector3* dividend, const double divisor)
|
||||
{
|
||||
bgc_fp64_dual_vector3_multiply(quotient, dividend, 1.0 / divisor);
|
||||
if (bgc_fp64_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double multiplier = 1.0 / divisor;
|
||||
|
||||
bgc_fp64_vector3_multiply_by_real("ient->real, ÷nd->real, multiplier);
|
||||
bgc_fp64_vector3_multiply_by_real("ient->dual, ÷nd->dual, multiplier);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================ Mean of Two ================= //
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ inline void bgc_fp64_hg_vector3_swap(BGC_FP64_HgVector3* first, BGC_FP64_HgVecto
|
|||
inline int bgc_fp32_hg_vector3_rescale(BGC_FP32_HgVector3* homogeneous_vector, const float new_ratio)
|
||||
{
|
||||
if (bgc_fp32_is_zero(homogeneous_vector->d0)) {
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float multiplier = new_ratio / homogeneous_vector->d0;
|
||||
|
|
@ -202,13 +202,13 @@ inline int bgc_fp32_hg_vector3_rescale(BGC_FP32_HgVector3* homogeneous_vector, c
|
|||
homogeneous_vector->x3 *= multiplier;
|
||||
homogeneous_vector->d0 = new_ratio;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_hg_vector3_rescale(BGC_FP64_HgVector3* homogeneous_vector, const double new_ratio)
|
||||
{
|
||||
if (bgc_fp64_is_zero(homogeneous_vector->d0)) {
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double multiplier = new_ratio / homogeneous_vector->d0;
|
||||
|
|
@ -218,7 +218,7 @@ inline int bgc_fp64_hg_vector3_rescale(BGC_FP64_HgVector3* homogeneous_vector, c
|
|||
homogeneous_vector->x3 *= multiplier;
|
||||
homogeneous_vector->d0 = new_ratio;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ extern inline void bgc_fp64_matrix2x2_subtract(BGC_FP64_Matrix2x2* difference, c
|
|||
extern inline void bgc_fp32_matrix2x2_multiply(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix2x2* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_matrix2x2_multiply(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix2x2* multiplicand, const double multiplier);
|
||||
|
||||
extern inline void bgc_fp32_matrix2x2_divide(BGC_FP32_Matrix2x2* quotient, const BGC_FP32_Matrix2x2* dividend, const float divisor);
|
||||
extern inline void bgc_fp64_matrix2x2_divide(BGC_FP64_Matrix2x2* quotient, const BGC_FP64_Matrix2x2* dividend, const double divisor);
|
||||
extern inline int bgc_fp32_matrix2x2_divide(BGC_FP32_Matrix2x2* quotient, const BGC_FP32_Matrix2x2* dividend, const float divisor);
|
||||
extern inline int bgc_fp64_matrix2x2_divide(BGC_FP64_Matrix2x2* quotient, const BGC_FP64_Matrix2x2* dividend, const double divisor);
|
||||
|
||||
extern inline void bgc_fp32_matrix2x2_interpolate(BGC_FP32_Matrix2x2* interpolation, const BGC_FP32_Matrix2x2* first, const BGC_FP32_Matrix2x2* second, const float phase);
|
||||
extern inline void bgc_fp64_matrix2x2_interpolate(BGC_FP64_Matrix2x2* interpolation, const BGC_FP64_Matrix2x2* first, const BGC_FP64_Matrix2x2* second, const double phase);
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ inline int bgc_fp32_matrix2x2_get_inverse(BGC_FP32_Matrix2x2* inverse, const BGC
|
|||
const float determinant = bgc_fp32_matrix2x2_get_determinant(matrix);
|
||||
|
||||
if (bgc_fp32_is_zero(determinant)) {
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float r1c1 = matrix->r2c2;
|
||||
|
|
@ -259,7 +259,7 @@ inline int bgc_fp32_matrix2x2_get_inverse(BGC_FP32_Matrix2x2* inverse, const BGC
|
|||
inverse->r2c1 = r2c1 * multiplier;
|
||||
inverse->r2c2 = r2c2 * multiplier;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_matrix2x2_get_inverse(BGC_FP64_Matrix2x2* inverse, const BGC_FP64_Matrix2x2* matrix)
|
||||
|
|
@ -267,7 +267,7 @@ inline int bgc_fp64_matrix2x2_get_inverse(BGC_FP64_Matrix2x2* inverse, const BGC
|
|||
const double determinant = bgc_fp64_matrix2x2_get_determinant(matrix);
|
||||
|
||||
if (bgc_fp64_is_zero(determinant)) {
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double r1c1 = matrix->r2c2;
|
||||
|
|
@ -284,7 +284,7 @@ inline int bgc_fp64_matrix2x2_get_inverse(BGC_FP64_Matrix2x2* inverse, const BGC
|
|||
inverse->r2c1 = r2c1 * multiplier;
|
||||
inverse->r2c2 = r2c2 * multiplier;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// =================== Invert =================== //
|
||||
|
|
@ -557,14 +557,24 @@ inline void bgc_fp64_matrix2x2_multiply(BGC_FP64_Matrix2x2* product, const BGC_F
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_fp32_matrix2x2_divide(BGC_FP32_Matrix2x2* quotient, const BGC_FP32_Matrix2x2* dividend, const float divisor)
|
||||
inline int bgc_fp32_matrix2x2_divide(BGC_FP32_Matrix2x2* quotient, const BGC_FP32_Matrix2x2* dividend, const float divisor)
|
||||
{
|
||||
if (bgc_fp32_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_matrix2x2_multiply(quotient, dividend, 1.0f / divisor);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix2x2_divide(BGC_FP64_Matrix2x2* quotient, const BGC_FP64_Matrix2x2* dividend, const double divisor)
|
||||
inline int bgc_fp64_matrix2x2_divide(BGC_FP64_Matrix2x2* quotient, const BGC_FP64_Matrix2x2* dividend, const double divisor)
|
||||
{
|
||||
if (bgc_fp64_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_matrix2x2_multiply(quotient, dividend, 1.0 / divisor);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================ Interpolate ================= //
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ extern inline void bgc_fp64_matrix2x3_subtract(BGC_FP64_Matrix2x3* difference, c
|
|||
extern inline void bgc_fp32_matrix2x3_multiply(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix2x3* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_matrix2x3_multiply(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix2x3* multiplicand, const double multiplier);
|
||||
|
||||
extern inline void bgc_fp32_matrix2x3_divide(BGC_FP32_Matrix2x3* quotient, const BGC_FP32_Matrix2x3* dividend, const float divisor);
|
||||
extern inline void bgc_fp64_matrix2x3_divide(BGC_FP64_Matrix2x3* quotient, const BGC_FP64_Matrix2x3* dividend, const double divisor);
|
||||
extern inline int bgc_fp32_matrix2x3_divide(BGC_FP32_Matrix2x3* quotient, const BGC_FP32_Matrix2x3* dividend, const float divisor);
|
||||
extern inline int bgc_fp64_matrix2x3_divide(BGC_FP64_Matrix2x3* quotient, const BGC_FP64_Matrix2x3* dividend, const double divisor);
|
||||
|
||||
extern inline void bgc_fp32_matrix2x3_interpolate(BGC_FP32_Matrix2x3* interpolation, const BGC_FP32_Matrix2x3* first, const BGC_FP32_Matrix2x3* second, const float phase);
|
||||
extern inline void bgc_fp64_matrix2x3_interpolate(BGC_FP64_Matrix2x3* interpolation, const BGC_FP64_Matrix2x3* first, const BGC_FP64_Matrix2x3* second, const double phase);
|
||||
|
|
|
|||
|
|
@ -437,14 +437,24 @@ inline void bgc_fp64_matrix2x3_multiply(BGC_FP64_Matrix2x3* product, const BGC_F
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_fp32_matrix2x3_divide(BGC_FP32_Matrix2x3* quotient, const BGC_FP32_Matrix2x3* dividend, const float divisor)
|
||||
inline int bgc_fp32_matrix2x3_divide(BGC_FP32_Matrix2x3* quotient, const BGC_FP32_Matrix2x3* dividend, const float divisor)
|
||||
{
|
||||
if (bgc_fp32_is_zero(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_matrix2x3_multiply(quotient, dividend, 1.0f / divisor);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix2x3_divide(BGC_FP64_Matrix2x3* quotient, const BGC_FP64_Matrix2x3* dividend, const double divisor)
|
||||
inline int bgc_fp64_matrix2x3_divide(BGC_FP64_Matrix2x3* quotient, const BGC_FP64_Matrix2x3* dividend, const double divisor)
|
||||
{
|
||||
if (bgc_fp64_is_zero(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_matrix2x3_multiply(quotient, dividend, 1.0 / divisor);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================ Interpolate ================= //
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ extern inline void bgc_fp64_matrix3x2_subtract(BGC_FP64_Matrix3x2* difference, c
|
|||
extern inline void bgc_fp32_matrix3x2_multiply(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix3x2* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_matrix3x2_multiply(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix3x2* multiplicand, const double multiplier);
|
||||
|
||||
extern inline void bgc_fp32_matrix3x2_divide(BGC_FP32_Matrix3x2* quotient, const BGC_FP32_Matrix3x2* dividend, const float divisor);
|
||||
extern inline void bgc_fp64_matrix3x2_divide(BGC_FP64_Matrix3x2* quotient, const BGC_FP64_Matrix3x2* dividend, const double divisor);
|
||||
extern inline int bgc_fp32_matrix3x2_divide(BGC_FP32_Matrix3x2* quotient, const BGC_FP32_Matrix3x2* dividend, const float divisor);
|
||||
extern inline int bgc_fp64_matrix3x2_divide(BGC_FP64_Matrix3x2* quotient, const BGC_FP64_Matrix3x2* dividend, const double divisor);
|
||||
|
||||
extern inline void bgc_fp32_matrix3x2_interpolate(BGC_FP32_Matrix3x2* interpolation, const BGC_FP32_Matrix3x2* first, const BGC_FP32_Matrix3x2* second, const float phase);
|
||||
extern inline void bgc_fp64_matrix3x2_interpolate(BGC_FP64_Matrix3x2* interpolation, const BGC_FP64_Matrix3x2* first, const BGC_FP64_Matrix3x2* second, const double phase);
|
||||
|
|
|
|||
|
|
@ -445,14 +445,24 @@ inline void bgc_fp64_matrix3x2_multiply(BGC_FP64_Matrix3x2* product, const BGC_F
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_fp32_matrix3x2_divide(BGC_FP32_Matrix3x2* quotient, const BGC_FP32_Matrix3x2* dividend, const float divisor)
|
||||
inline int bgc_fp32_matrix3x2_divide(BGC_FP32_Matrix3x2* quotient, const BGC_FP32_Matrix3x2* dividend, const float divisor)
|
||||
{
|
||||
if (bgc_fp32_is_zero(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_matrix3x2_multiply(quotient, dividend, 1.0f / divisor);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix3x2_divide(BGC_FP64_Matrix3x2* quotient, const BGC_FP64_Matrix3x2* dividend, const double divisor)
|
||||
inline int bgc_fp64_matrix3x2_divide(BGC_FP64_Matrix3x2* quotient, const BGC_FP64_Matrix3x2* dividend, const double divisor)
|
||||
{
|
||||
if (bgc_fp64_is_zero(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_matrix3x2_multiply(quotient, dividend, 1.0 / divisor);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================ Interpolate ================= //
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ extern inline void bgc_fp64_matrix3x3_subtract(BGC_FP64_Matrix3x3* difference, c
|
|||
extern inline void bgc_fp32_matrix3x3_multiply(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix3x3* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_matrix3x3_multiply(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix3x3* multiplicand, const double multiplier);
|
||||
|
||||
extern inline void bgc_fp32_matrix3x3_divide(BGC_FP32_Matrix3x3* quotient, const BGC_FP32_Matrix3x3* dividend, const float divisor);
|
||||
extern inline void bgc_fp64_matrix3x3_divide(BGC_FP64_Matrix3x3* quotient, const BGC_FP64_Matrix3x3* dividend, const double divisor);
|
||||
extern inline int bgc_fp32_matrix3x3_divide(BGC_FP32_Matrix3x3* quotient, const BGC_FP32_Matrix3x3* dividend, const float divisor);
|
||||
extern inline int bgc_fp64_matrix3x3_divide(BGC_FP64_Matrix3x3* quotient, const BGC_FP64_Matrix3x3* dividend, const double divisor);
|
||||
|
||||
extern inline void bgc_fp32_matrix3x3_interpolate(BGC_FP32_Matrix3x3* interpolation, const BGC_FP32_Matrix3x3* first, const BGC_FP32_Matrix3x3* second, const float phase);
|
||||
extern inline void bgc_fp64_matrix3x3_interpolate(BGC_FP64_Matrix3x3* interpolation, const BGC_FP64_Matrix3x3* first, const BGC_FP64_Matrix3x3* second, const double phase);
|
||||
|
|
@ -82,7 +82,7 @@ int bgc_fp32_matrix3x3_get_inverse(BGC_FP32_Matrix3x3* inverse, const BGC_FP32_M
|
|||
const float determinant = bgc_fp32_matrix3x3_get_determinant(matrix);
|
||||
|
||||
if (bgc_fp32_is_zero(determinant)) {
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float r1c1 = matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2;
|
||||
|
|
@ -111,7 +111,7 @@ int bgc_fp32_matrix3x3_get_inverse(BGC_FP32_Matrix3x3* inverse, const BGC_FP32_M
|
|||
inverse->r3c2 = r3c2 * multiplier;
|
||||
inverse->r3c3 = r3c3 * multiplier;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
int bgc_fp64_matrix3x3_get_inverse(BGC_FP64_Matrix3x3* inverse, const BGC_FP64_Matrix3x3* matrix)
|
||||
|
|
@ -119,7 +119,7 @@ int bgc_fp64_matrix3x3_get_inverse(BGC_FP64_Matrix3x3* inverse, const BGC_FP64_M
|
|||
const double determinant = bgc_fp64_matrix3x3_get_determinant(matrix);
|
||||
|
||||
if (bgc_fp64_is_zero(determinant)) {
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double r1c1 = matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2;
|
||||
|
|
@ -148,5 +148,5 @@ int bgc_fp64_matrix3x3_get_inverse(BGC_FP64_Matrix3x3* inverse, const BGC_FP64_M
|
|||
inverse->r3c2 = r3c2 * multiplier;
|
||||
inverse->r3c3 = r3c3 * multiplier;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -784,14 +784,24 @@ inline void bgc_fp64_matrix3x3_multiply(BGC_FP64_Matrix3x3* product, const BGC_F
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_fp32_matrix3x3_divide(BGC_FP32_Matrix3x3* quotient, const BGC_FP32_Matrix3x3* dividend, const float divisor)
|
||||
inline int bgc_fp32_matrix3x3_divide(BGC_FP32_Matrix3x3* quotient, const BGC_FP32_Matrix3x3* dividend, const float divisor)
|
||||
{
|
||||
if (bgc_fp32_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_matrix3x3_multiply(quotient, dividend, 1.0f / divisor);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix3x3_divide(BGC_FP64_Matrix3x3* quotient, const BGC_FP64_Matrix3x3* dividend, const double divisor)
|
||||
inline int bgc_fp64_matrix3x3_divide(BGC_FP64_Matrix3x3* quotient, const BGC_FP64_Matrix3x3* dividend, const double divisor)
|
||||
{
|
||||
if (bgc_fp64_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_matrix3x3_multiply(quotient, dividend, 1.0 / divisor);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================ Interpolate ================= //
|
||||
|
|
|
|||
|
|
@ -40,20 +40,23 @@ extern inline void bgc_fp64_quaternion_add_scaled(BGC_FP64_Quaternion* sum, cons
|
|||
extern inline void bgc_fp32_quaternion_subtract(BGC_FP32_Quaternion* difference, const BGC_FP32_Quaternion* minuend, const BGC_FP32_Quaternion* subtrahend);
|
||||
extern inline void bgc_fp64_quaternion_subtract(BGC_FP64_Quaternion* difference, const BGC_FP64_Quaternion* minuend, const BGC_FP64_Quaternion* subtrahend);
|
||||
|
||||
extern inline void bgc_fp32_quaternion_multiply_by_real(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* multiplicand, const float multipier);
|
||||
extern inline void bgc_fp64_quaternion_multiply_by_real(BGC_FP64_Quaternion* product, const BGC_FP64_Quaternion* multiplicand, const double multipier);
|
||||
|
||||
extern inline void bgc_fp32_quaternion_multiply_by_quaternion(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* left, const BGC_FP32_Quaternion* right);
|
||||
extern inline void bgc_fp64_quaternion_multiply_by_quaternion(BGC_FP64_Quaternion* product, const BGC_FP64_Quaternion* left, const BGC_FP64_Quaternion* right);
|
||||
|
||||
extern inline void bgc_fp32_quaternion_multiply_by_conjugate(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* left, const BGC_FP32_Quaternion* right);
|
||||
extern inline void bgc_fp64_quaternion_multiply_by_conjugate(BGC_FP64_Quaternion* product, const BGC_FP64_Quaternion* left, const BGC_FP64_Quaternion* right);
|
||||
|
||||
extern inline void bgc_fp32_quaternion_multiply_by_number(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* multiplicand, const float multipier);
|
||||
extern inline void bgc_fp64_quaternion_multiply_by_number(BGC_FP64_Quaternion* product, const BGC_FP64_Quaternion* multiplicand, const double multipier);
|
||||
extern inline int bgc_fp32_quaternion_divide_by_real(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* dividend, const float divisor);
|
||||
extern inline int bgc_fp64_quaternion_divide_by_real(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* dividend, const double divisor);
|
||||
|
||||
extern inline int bgc_fp32_quaternion_divide_by_quaternion(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* divident, const BGC_FP32_Quaternion* divisor);
|
||||
extern inline int bgc_fp64_quaternion_divide_by_quaternion(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* divident, const BGC_FP64_Quaternion* divisor);
|
||||
|
||||
extern inline void bgc_fp32_quaternion_divide_by_number(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* dividend, const float divisor);
|
||||
extern inline void bgc_fp64_quaternion_divide_by_number(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* dividend, const double divisor);
|
||||
extern inline int bgc_fp32_quaternion_divide_by_conjugate(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* divident, const BGC_FP32_Quaternion* divisor_to_conjugate);
|
||||
extern inline int bgc_fp64_quaternion_divide_by_conjugate(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* divident, const BGC_FP64_Quaternion* divisor_to_conjugate);
|
||||
|
||||
extern inline void bgc_fp32_quaternion_get_mean2(BGC_FP32_Quaternion* mean, const BGC_FP32_Quaternion* quaternion1, const BGC_FP32_Quaternion* quaternion2);
|
||||
extern inline void bgc_fp64_quaternion_get_mean2(BGC_FP64_Quaternion* mean, const BGC_FP64_Quaternion* quaternion1, const BGC_FP64_Quaternion* quaternion2);
|
||||
|
|
|
|||
|
|
@ -246,7 +246,25 @@ inline void bgc_fp64_quaternion_subtract(BGC_FP64_Quaternion* difference, const
|
|||
difference->x3 = minuend->x3 - subtrahend->x3;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
// ============= Multiply By Number ============= //
|
||||
|
||||
inline void bgc_fp32_quaternion_multiply_by_real(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* multiplicand, const float multipier)
|
||||
{
|
||||
product->s0 = multiplicand->s0 * multipier;
|
||||
product->x1 = multiplicand->x1 * multipier;
|
||||
product->x2 = multiplicand->x2 * multipier;
|
||||
product->x3 = multiplicand->x3 * multipier;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_quaternion_multiply_by_real(BGC_FP64_Quaternion* product, const BGC_FP64_Quaternion* multiplicand, const double multipier)
|
||||
{
|
||||
product->s0 = multiplicand->s0 * multipier;
|
||||
product->x1 = multiplicand->x1 * multipier;
|
||||
product->x2 = multiplicand->x2 * multipier;
|
||||
product->x3 = multiplicand->x3 * multipier;
|
||||
}
|
||||
|
||||
// =========== Multiply By Quaternion =========== //
|
||||
|
||||
inline void bgc_fp32_quaternion_multiply_by_quaternion(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* left, const BGC_FP32_Quaternion* right)
|
||||
{
|
||||
|
|
@ -274,6 +292,8 @@ inline void bgc_fp64_quaternion_multiply_by_quaternion(BGC_FP64_Quaternion* prod
|
|||
product->x3 = x3;
|
||||
}
|
||||
|
||||
// ====== Multiply By Conjugate Quaternion ====== //
|
||||
|
||||
inline void bgc_fp32_quaternion_multiply_by_conjugate(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* left, const BGC_FP32_Quaternion* right)
|
||||
{
|
||||
const float s0 = (left->s0 * right->s0 + left->x1 * right->x1) + (left->x2 * right->x2 + left->x3 * right->x3);
|
||||
|
|
@ -300,43 +320,42 @@ inline void bgc_fp64_quaternion_multiply_by_conjugate(BGC_FP64_Quaternion* produ
|
|||
product->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_fp32_quaternion_multiply_by_number(BGC_FP32_Quaternion* product, const BGC_FP32_Quaternion* multiplicand, const float multipier)
|
||||
// ============== Divide By Number ============== //
|
||||
|
||||
inline int bgc_fp32_quaternion_divide_by_real(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* dividend, const float divisor)
|
||||
{
|
||||
product->s0 = multiplicand->s0 * multipier;
|
||||
product->x1 = multiplicand->x1 * multipier;
|
||||
product->x2 = multiplicand->x2 * multipier;
|
||||
product->x3 = multiplicand->x3 * multipier;
|
||||
if (bgc_fp32_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_quaternion_multiply_by_real(quotient, dividend, 1.0f / divisor);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_quaternion_multiply_by_number(BGC_FP64_Quaternion* product, const BGC_FP64_Quaternion* multiplicand, const double multipier)
|
||||
inline int bgc_fp64_quaternion_divide_by_real(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* dividend, const double divisor)
|
||||
{
|
||||
product->s0 = multiplicand->s0 * multipier;
|
||||
product->x1 = multiplicand->x1 * multipier;
|
||||
product->x2 = multiplicand->x2 * multipier;
|
||||
product->x3 = multiplicand->x3 * multipier;
|
||||
if (bgc_fp64_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_quaternion_multiply_by_real(quotient, dividend, 1.0 / divisor);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// =================== Divide =================== //
|
||||
// ============ Divide By Quaternion ============ //
|
||||
|
||||
inline int bgc_fp32_quaternion_divide_by_quaternion(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* divident, const BGC_FP32_Quaternion* divisor)
|
||||
{
|
||||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(divisor);
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float s0 = (divident->s0 * divisor->s0 + divident->x1 * divisor->x1) + (divident->x2 * divisor->x2 + divident->x3 * divisor->x3);
|
||||
const float x1 = (divident->x1 * divisor->s0 + divident->x3 * divisor->x2) - (divident->s0 * divisor->x1 + divident->x2 * divisor->x3);
|
||||
const float x2 = (divident->x2 * divisor->s0 + divident->x1 * divisor->x3) - (divident->s0 * divisor->x2 + divident->x3 * divisor->x1);
|
||||
const float x3 = (divident->x3 * divisor->s0 + divident->x2 * divisor->x1) - (divident->s0 * divisor->x3 + divident->x1 * divisor->x2);
|
||||
|
||||
const float multiplicand = 1.0f / square_modulus;
|
||||
|
||||
quotient->s0 = s0 * multiplicand;
|
||||
quotient->x1 = x1 * multiplicand;
|
||||
quotient->x2 = x2 * multiplicand;
|
||||
quotient->x3 = x3 * multiplicand;
|
||||
bgc_fp32_quaternion_multiply_by_conjugate(quotient, divident, divisor);
|
||||
bgc_fp32_quaternion_multiply_by_real(quotient, quotient, 1.0f / square_modulus);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
|
@ -346,32 +365,43 @@ inline int bgc_fp64_quaternion_divide_by_quaternion(BGC_FP64_Quaternion* quotien
|
|||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(divisor);
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double s0 = (divident->s0 * divisor->s0 + divident->x1 * divisor->x1) + (divident->x2 * divisor->x2 + divident->x3 * divisor->x3);
|
||||
const double x1 = (divident->x1 * divisor->s0 + divident->x3 * divisor->x2) - (divident->s0 * divisor->x1 + divident->x2 * divisor->x3);
|
||||
const double x2 = (divident->x2 * divisor->s0 + divident->x1 * divisor->x3) - (divident->s0 * divisor->x2 + divident->x3 * divisor->x1);
|
||||
const double x3 = (divident->x3 * divisor->s0 + divident->x2 * divisor->x1) - (divident->s0 * divisor->x3 + divident->x1 * divisor->x2);
|
||||
|
||||
const double multiplicand = 1.0 / square_modulus;
|
||||
|
||||
quotient->s0 = s0 * multiplicand;
|
||||
quotient->x1 = x1 * multiplicand;
|
||||
quotient->x2 = x2 * multiplicand;
|
||||
quotient->x3 = x3 * multiplicand;
|
||||
bgc_fp64_quaternion_multiply_by_conjugate(quotient, divident, divisor);
|
||||
bgc_fp64_quaternion_multiply_by_real(quotient, quotient, 1.0 / square_modulus);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp32_quaternion_divide_by_number(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* dividend, const float divisor)
|
||||
// ======= Divide By Conjugate Quaternion ======= //
|
||||
|
||||
inline int bgc_fp32_quaternion_divide_by_conjugate(BGC_FP32_Quaternion* quotient, const BGC_FP32_Quaternion* divident, const BGC_FP32_Quaternion* divisor_to_conjugate)
|
||||
{
|
||||
bgc_fp32_quaternion_multiply_by_number(quotient, dividend, 1.0f / divisor);
|
||||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(divisor_to_conjugate);
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_quaternion_multiply_by_quaternion(quotient, divisor_to_conjugate, divisor);
|
||||
bgc_fp32_quaternion_multiply_by_real(quotient, quotient, 1.0f / square_modulus);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_quaternion_divide_by_number(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* dividend, const double divisor)
|
||||
inline int bgc_fp64_quaternion_divide_by_conjugate(BGC_FP64_Quaternion* quotient, const BGC_FP64_Quaternion* divident, const BGC_FP64_Quaternion* divisor_to_conjugate)
|
||||
{
|
||||
bgc_fp64_quaternion_multiply_by_number(quotient, dividend, 1.0 / divisor);
|
||||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(divisor_to_conjugate);
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_quaternion_multiply_by_quaternion(quotient, divisor_to_conjugate, divisor);
|
||||
bgc_fp64_quaternion_multiply_by_real(quotient, quotient, 1.0 / square_modulus);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================ Mean of Two ================= //
|
||||
|
|
@ -505,7 +535,7 @@ inline int bgc_fp32_quaternion_get_inverse(BGC_FP32_Quaternion* inverse, const B
|
|||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float multiplicand = 1.0f / square_modulus;
|
||||
|
|
@ -523,7 +553,7 @@ inline int bgc_fp64_quaternion_get_inverse(BGC_FP64_Quaternion* inverse, const B
|
|||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double multiplicand = 1.0 / square_modulus;
|
||||
|
|
@ -552,12 +582,12 @@ inline int bgc_fp32_quaternion_normalize(BGC_FP32_Quaternion* quaternion)
|
|||
{
|
||||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
return BGC_SUCCESS;
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILED;
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
|
@ -574,12 +604,12 @@ inline int bgc_fp64_quaternion_normalize(BGC_FP64_Quaternion* quaternion)
|
|||
{
|
||||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
return BGC_SUCCESS;
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILED;
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
|
@ -596,17 +626,17 @@ inline int bgc_fp32_quaternion_get_normalized(BGC_FP32_Quaternion* normalized, c
|
|||
{
|
||||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
bgc_fp32_quaternion_reset(normalized);
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
bgc_fp32_quaternion_copy(normalized, quaternion);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
bgc_fp32_quaternion_reset(normalized);
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
bgc_fp32_quaternion_multiply_by_number(normalized, quaternion, sqrtf(1.0f / square_modulus));
|
||||
bgc_fp32_quaternion_multiply_by_real(normalized, quaternion, sqrtf(1.0f / square_modulus));
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -614,17 +644,17 @@ inline int bgc_fp64_quaternion_get_normalized(BGC_FP64_Quaternion* normalized, c
|
|||
{
|
||||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
bgc_fp64_quaternion_reset(normalized);
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
bgc_fp64_quaternion_copy(normalized, quaternion);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
bgc_fp64_quaternion_reset(normalized);
|
||||
return BGC_FAILED;
|
||||
}
|
||||
|
||||
bgc_fp64_quaternion_multiply_by_number(normalized, quaternion, sqrt(1.0 / square_modulus));
|
||||
bgc_fp64_quaternion_multiply_by_real(normalized, quaternion, sqrt(1.0 / square_modulus));
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -709,7 +739,7 @@ inline int bgc_fp32_quaternion_turn_vector(BGC_FP32_Vector3* turned_vector, cons
|
|||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (square_modulus < BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float multiplier = 2.0f / square_modulus;
|
||||
|
|
@ -735,7 +765,7 @@ inline int bgc_fp64_quaternion_turn_vector(BGC_FP64_Vector3* turned_vector, cons
|
|||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (square_modulus < BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double multiplier = 2.0 / square_modulus;
|
||||
|
|
@ -763,7 +793,7 @@ inline int bgc_fp32_quaternion_turn_vector_back(BGC_FP32_Vector3* turned_vector,
|
|||
const float square_modulus = bgc_fp32_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (square_modulus < BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float multiplier = 2.0f / square_modulus;
|
||||
|
|
@ -789,7 +819,7 @@ inline int bgc_fp64_quaternion_turn_vector_back(BGC_FP64_Vector3* turned_vector,
|
|||
const double square_modulus = bgc_fp64_quaternion_get_square_modulus(quaternion);
|
||||
|
||||
if (square_modulus < BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double multiplier = 2.0 / square_modulus;
|
||||
|
|
@ -824,7 +854,7 @@ inline int bgc_fp32_quaternion_get_rotation_matrix(BGC_FP32_Matrix3x3* rotation,
|
|||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus))
|
||||
{
|
||||
bgc_fp32_matrix3x3_make_identity(rotation);
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float corrector1 = 1.0f / square_modulus;
|
||||
|
|
@ -865,7 +895,7 @@ inline int bgc_fp64_quaternion_get_rotation_matrix(BGC_FP64_Matrix3x3* rotation,
|
|||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus))
|
||||
{
|
||||
bgc_fp64_matrix3x3_make_identity(rotation);
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double corrector1 = 1.0f / square_modulus;
|
||||
|
|
@ -908,7 +938,7 @@ inline int bgc_fp32_quaternion_get_reverse_matrix(BGC_FP32_Matrix3x3* reverse, c
|
|||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus))
|
||||
{
|
||||
bgc_fp32_matrix3x3_make_identity(reverse);
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const float corrector1 = 1.0f / square_modulus;
|
||||
|
|
@ -949,7 +979,7 @@ inline int bgc_fp64_quaternion_get_reverse_matrix(BGC_FP64_Matrix3x3* reverse, c
|
|||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus))
|
||||
{
|
||||
bgc_fp64_matrix3x3_make_identity(reverse);
|
||||
return BGC_FAILED;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
const double corrector1 = 1.0f / square_modulus;
|
||||
|
|
@ -975,29 +1005,29 @@ inline int bgc_fp64_quaternion_get_reverse_matrix(BGC_FP64_Matrix3x3* reverse, c
|
|||
reverse->r3c2 = corrector2 * (x2x3 - s0x1);
|
||||
reverse->r1c3 = corrector2 * (x1x3 - s0x2);
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ============= Get Both Matrixes ============== //
|
||||
|
||||
inline int bgc_fp32_quaternion_get_both_matrices(BGC_FP32_Matrix3x3* rotation, BGC_FP32_Matrix3x3* reverse, const BGC_FP32_Quaternion* quaternion)
|
||||
{
|
||||
if (bgc_fp32_quaternion_get_reverse_matrix(reverse, quaternion) == BGC_SUCCESS) {
|
||||
bgc_fp32_matrix3x3_get_transposed(rotation, reverse);
|
||||
return BGC_SUCCESS;
|
||||
if (bgc_fp32_quaternion_get_reverse_matrix(reverse, quaternion) != BGC_SUCCESS) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
return BGC_FAILED;
|
||||
bgc_fp32_matrix3x3_get_transposed(rotation, reverse);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_quaternion_get_both_matrices(BGC_FP64_Matrix3x3* rotation, BGC_FP64_Matrix3x3* reverse, const BGC_FP64_Quaternion* quaternion)
|
||||
{
|
||||
if (bgc_fp64_quaternion_get_reverse_matrix(reverse, quaternion) == BGC_SUCCESS) {
|
||||
bgc_fp64_matrix3x3_get_transposed(rotation, reverse);
|
||||
return BGC_SUCCESS;
|
||||
if (bgc_fp64_quaternion_get_reverse_matrix(reverse, quaternion) != BGC_SUCCESS) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
return BGC_FAILED;
|
||||
bgc_fp64_matrix3x3_get_transposed(rotation, reverse);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ void _bgc_fp32_turn3_normalize(BGC_FP32_Turn3* turn, const float square_modulus)
|
|||
return;
|
||||
}
|
||||
|
||||
bgc_fp32_quaternion_multiply_by_number(&turn->_versor, &turn->_versor, sqrtf(1.0f / square_modulus));
|
||||
bgc_fp32_quaternion_multiply_by_real(&turn->_versor, &turn->_versor, sqrtf(1.0f / square_modulus));
|
||||
}
|
||||
|
||||
void _bgc_fp64_turn3_normalize(BGC_FP64_Turn3* turn, const double square_modulus)
|
||||
|
|
@ -95,7 +95,7 @@ void _bgc_fp64_turn3_normalize(BGC_FP64_Turn3* turn, const double square_modulus
|
|||
return;
|
||||
}
|
||||
|
||||
bgc_fp64_quaternion_multiply_by_number(&turn->_versor, &turn->_versor, sqrt(1.0 / square_modulus));
|
||||
bgc_fp64_quaternion_multiply_by_real(&turn->_versor, &turn->_versor, sqrt(1.0 / square_modulus));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -308,7 +308,7 @@ static inline int _bgc_fp32_turn3_get_orthogonal_pair(BGC_FP32_Vector3* unit_mai
|
|||
return _BGC_ERROR_TURN3_EMPTY_BRANCH;
|
||||
}
|
||||
|
||||
bgc_fp32_vector3_multiply(unit_main, main, sqrtf(1.0f / main_square_modulus));
|
||||
bgc_fp32_vector3_multiply_by_real(unit_main, main, sqrtf(1.0f / main_square_modulus));
|
||||
|
||||
bgc_fp32_vector3_add_scaled(unit_branch, branch, unit_main, -bgc_fp32_vector3_get_dot_product(branch, unit_main));
|
||||
|
||||
|
|
@ -318,7 +318,7 @@ static inline int _bgc_fp32_turn3_get_orthogonal_pair(BGC_FP32_Vector3* unit_mai
|
|||
return _BGC_ERROR_TURN3_PAIR_PARALLEL;
|
||||
}
|
||||
|
||||
bgc_fp32_vector3_multiply(unit_branch, unit_branch, sqrtf(1.0f / orthogonal_square_modulus));
|
||||
bgc_fp32_vector3_multiply_by_real(unit_branch, unit_branch, sqrtf(1.0f / orthogonal_square_modulus));
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
|
@ -337,7 +337,7 @@ static inline int _bgc_fp64_turn3_get_orthogonal_pair(BGC_FP64_Vector3* unit_mai
|
|||
return _BGC_ERROR_TURN3_EMPTY_BRANCH;
|
||||
}
|
||||
|
||||
bgc_fp64_vector3_multiply(unit_main, main, sqrt(1.0 / main_square_modulus));
|
||||
bgc_fp64_vector3_multiply_by_real(unit_main, main, sqrt(1.0 / main_square_modulus));
|
||||
|
||||
bgc_fp64_vector3_add_scaled(unit_branch, branch, unit_main, -bgc_fp64_vector3_get_dot_product(branch, unit_main));
|
||||
|
||||
|
|
@ -347,7 +347,7 @@ static inline int _bgc_fp64_turn3_get_orthogonal_pair(BGC_FP64_Vector3* unit_mai
|
|||
return _BGC_ERROR_TURN3_PAIR_PARALLEL;
|
||||
}
|
||||
|
||||
bgc_fp64_vector3_multiply(unit_branch, unit_branch, sqrt(1.0 / orthogonal_square_modulus));
|
||||
bgc_fp64_vector3_multiply_by_real(unit_branch, unit_branch, sqrt(1.0 / orthogonal_square_modulus));
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#define BGC_FP64_GOLDEN_RATIO_LOW 0.61803398874989485
|
||||
|
||||
#define BGC_SUCCESS 0
|
||||
#define BGC_FAILED -1
|
||||
#define BGC_FAILURE -1
|
||||
|
||||
#define BGC_ATTITUDE_ANY 0
|
||||
#define BGC_ATTITUDE_ZERO 1
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@ extern inline void bgc_fp64_vector2_add_scaled(BGC_FP64_Vector2* sum, const BGC_
|
|||
extern inline void bgc_fp32_vector2_subtract(BGC_FP32_Vector2* difference, const BGC_FP32_Vector2* minuend, const BGC_FP32_Vector2* subtrahend);
|
||||
extern inline void bgc_fp64_vector2_subtract(BGC_FP64_Vector2* difference, const BGC_FP64_Vector2* minuend, const BGC_FP64_Vector2* subtrahend);
|
||||
|
||||
extern inline void bgc_fp32_vector2_multiply(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_vector2_multiply(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* multiplicand, const double multiplier);
|
||||
extern inline void bgc_fp32_vector2_multiply_by_real(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_vector2_multiply_by_real(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* multiplicand, const double multiplier);
|
||||
|
||||
extern inline void bgc_fp32_vector2_divide(BGC_FP32_Vector2* quotient, const BGC_FP32_Vector2* dividend, const float divisor);
|
||||
extern inline void bgc_fp64_vector2_divide(BGC_FP64_Vector2* quotient, const BGC_FP64_Vector2* dividend, const double divisor);
|
||||
extern inline int bgc_fp32_vector2_divide_by_real(BGC_FP32_Vector2* quotient, const BGC_FP32_Vector2* dividend, const float divisor);
|
||||
extern inline int bgc_fp64_vector2_divide_by_real(BGC_FP64_Vector2* quotient, const BGC_FP64_Vector2* dividend, const double divisor);
|
||||
|
||||
extern inline void bgc_fp32_vector2_get_mean2(BGC_FP32_Vector2* mean, const BGC_FP32_Vector2* vector1, const BGC_FP32_Vector2* vector2);
|
||||
extern inline void bgc_fp64_vector2_get_mean2(BGC_FP64_Vector2* mean, const BGC_FP64_Vector2* vector1, const BGC_FP64_Vector2* vector2);
|
||||
|
|
@ -97,14 +97,14 @@ float bgc_fp32_vector2_get_angle(const BGC_FP32_Vector2* vector1, const BGC_FP32
|
|||
const float square_modulus1 = bgc_fp32_vector2_get_square_modulus(vector1);
|
||||
|
||||
// square_modulus1 != square_modulus1 is check for NaN value at square_modulus1
|
||||
if (square_modulus1 <= BGC_FP32_SQUARE_EPSILON || square_modulus1 != square_modulus1) {
|
||||
if (square_modulus1 <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus1)) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float square_modulus2 = bgc_fp32_vector2_get_square_modulus(vector2);
|
||||
|
||||
// square_modulus2 != square_modulus2 is check for NaN value at square_modulus2
|
||||
if (square_modulus2 <= BGC_FP32_SQUARE_EPSILON || square_modulus2 != square_modulus2) {
|
||||
if (square_modulus2 <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus2)) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
|
@ -122,14 +122,14 @@ double bgc_fp64_vector2_get_angle(const BGC_FP64_Vector2* vector1, const BGC_FP6
|
|||
const double square_modulus1 = bgc_fp64_vector2_get_square_modulus(vector1);
|
||||
|
||||
// square_modulus1 != square_modulus1 is check for NaN value at square_modulus1
|
||||
if (square_modulus1 <= BGC_FP64_SQUARE_EPSILON || square_modulus1 != square_modulus1) {
|
||||
if (square_modulus1 <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus1)) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double square_modulus2 = bgc_fp64_vector2_get_square_modulus(vector2);
|
||||
|
||||
// square_modulus2 != square_modulus2 is check for NaN value at square_modulus2
|
||||
if (square_modulus2 <= BGC_FP64_SQUARE_EPSILON || square_modulus2 != square_modulus2) {
|
||||
if (square_modulus2 <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus2)) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -186,13 +186,13 @@ inline void bgc_fp64_vector2_subtract(BGC_FP64_Vector2* difference, const BGC_FP
|
|||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_fp32_vector2_multiply(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* multiplicand, const float multiplier)
|
||||
inline void bgc_fp32_vector2_multiply_by_real(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* multiplicand, const float multiplier)
|
||||
{
|
||||
product->x1 = multiplicand->x1 * multiplier;
|
||||
product->x2 = multiplicand->x2 * multiplier;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_vector2_multiply(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* multiplicand, const double multiplier)
|
||||
inline void bgc_fp64_vector2_multiply_by_real(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* multiplicand, const double multiplier)
|
||||
{
|
||||
product->x1 = multiplicand->x1 * multiplier;
|
||||
product->x2 = multiplicand->x2 * multiplier;
|
||||
|
|
@ -200,14 +200,26 @@ inline void bgc_fp64_vector2_multiply(BGC_FP64_Vector2* product, const BGC_FP64_
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_fp32_vector2_divide(BGC_FP32_Vector2* quotient, const BGC_FP32_Vector2* dividend, const float divisor)
|
||||
inline int bgc_fp32_vector2_divide_by_real(BGC_FP32_Vector2* quotient, const BGC_FP32_Vector2* dividend, const float divisor)
|
||||
{
|
||||
bgc_fp32_vector2_multiply(quotient, dividend, 1.0f / divisor);
|
||||
if (bgc_fp32_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_vector2_multiply_by_real(quotient, dividend, 1.0f / divisor);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_vector2_divide(BGC_FP64_Vector2* quotient, const BGC_FP64_Vector2* dividend, const double divisor)
|
||||
inline int bgc_fp64_vector2_divide_by_real(BGC_FP64_Vector2* quotient, const BGC_FP64_Vector2* dividend, const double divisor)
|
||||
{
|
||||
bgc_fp64_vector2_multiply(quotient, dividend, 1.0 / divisor);
|
||||
if (bgc_fp32_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_vector2_multiply_by_real(quotient, dividend, 1.0 / divisor);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================ Mean of Two ================= //
|
||||
|
|
@ -288,12 +300,12 @@ inline int bgc_fp32_vector2_normalize(BGC_FP32_Vector2* vector)
|
|||
{
|
||||
const float square_modulus = bgc_fp32_vector2_get_square_modulus(vector);
|
||||
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
return 1;
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return 0;
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
|
@ -301,19 +313,19 @@ inline int bgc_fp32_vector2_normalize(BGC_FP32_Vector2* vector)
|
|||
vector->x1 *= multiplier;
|
||||
vector->x2 *= multiplier;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_vector2_normalize(BGC_FP64_Vector2* vector)
|
||||
{
|
||||
const double square_modulus = bgc_fp64_vector2_get_square_modulus(vector);
|
||||
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
return 1;
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return 0;
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
|
@ -321,43 +333,43 @@ inline int bgc_fp64_vector2_normalize(BGC_FP64_Vector2* vector)
|
|||
vector->x1 *= multiplier;
|
||||
vector->x2 *= multiplier;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp32_vector2_get_normalized(BGC_FP32_Vector2* normalized, const BGC_FP32_Vector2* vector)
|
||||
{
|
||||
const float square_modulus = bgc_fp32_vector2_get_square_modulus(vector);
|
||||
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
bgc_fp32_vector2_copy(normalized, vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
bgc_fp32_vector2_reset(normalized);
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_vector2_multiply(normalized, vector, sqrtf(1.0f / square_modulus));
|
||||
return 1;
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
bgc_fp32_vector2_copy(normalized, vector);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
bgc_fp32_vector2_multiply_by_real(normalized, vector, sqrtf(1.0f / square_modulus));
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_vector2_get_normalized(BGC_FP64_Vector2* normalized, const BGC_FP64_Vector2* vector)
|
||||
{
|
||||
const double square_modulus = bgc_fp64_vector2_get_square_modulus(vector);
|
||||
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
bgc_fp64_vector2_copy(normalized, vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
bgc_fp64_vector2_reset(normalized);
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_vector2_multiply(normalized, vector, sqrt(1.0 / square_modulus));
|
||||
return 1;
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
bgc_fp64_vector2_copy(normalized, vector);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
bgc_fp64_vector2_multiply_by_real(normalized, vector, sqrt(1.0 / square_modulus));
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ============= Get Scalar Product ============= //
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@ extern inline void bgc_fp64_vector3_add_scaled(BGC_FP64_Vector3* sum, const BGC_
|
|||
extern inline void bgc_fp32_vector3_subtract(BGC_FP32_Vector3* difference, const BGC_FP32_Vector3* minuend, const BGC_FP32_Vector3* subtrahend);
|
||||
extern inline void bgc_fp64_vector3_subtract(BGC_FP64_Vector3* difference, const BGC_FP64_Vector3* minuend, const BGC_FP64_Vector3* subtrahend);
|
||||
|
||||
extern inline void bgc_fp32_vector3_multiply(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_vector3_multiply(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* multiplicand, const double multiplier);
|
||||
extern inline void bgc_fp32_vector3_multiply_by_real(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* multiplicand, const float multiplier);
|
||||
extern inline void bgc_fp64_vector3_multiply_by_real(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* multiplicand, const double multiplier);
|
||||
|
||||
extern inline void bgc_fp32_vector3_divide(BGC_FP32_Vector3* quotient, const BGC_FP32_Vector3* dividend, const float divisor);
|
||||
extern inline void bgc_fp64_vector3_divide(BGC_FP64_Vector3* quotient, const BGC_FP64_Vector3* dividend, const double divisor);
|
||||
extern inline int bgc_fp32_vector3_divide_by_real(BGC_FP32_Vector3* quotient, const BGC_FP32_Vector3* dividend, const float divisor);
|
||||
extern inline int bgc_fp64_vector3_divide_by_real(BGC_FP64_Vector3* quotient, const BGC_FP64_Vector3* dividend, const double divisor);
|
||||
|
||||
extern inline void bgc_fp32_vector3_get_mean2(BGC_FP32_Vector3* mean, const BGC_FP32_Vector3* vector1, const BGC_FP32_Vector3* vector2);
|
||||
extern inline void bgc_fp64_vector3_get_mean2(BGC_FP64_Vector3* mean, const BGC_FP64_Vector3* vector1, const BGC_FP64_Vector3* vector2);
|
||||
|
|
|
|||
|
|
@ -208,14 +208,14 @@ inline void bgc_fp64_vector3_subtract(BGC_FP64_Vector3* difference, const BGC_FP
|
|||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_fp32_vector3_multiply(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* multiplicand, const float multiplier)
|
||||
inline void bgc_fp32_vector3_multiply_by_real(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* multiplicand, const float multiplier)
|
||||
{
|
||||
product->x1 = multiplicand->x1 * multiplier;
|
||||
product->x2 = multiplicand->x2 * multiplier;
|
||||
product->x3 = multiplicand->x3 * multiplier;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_vector3_multiply(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* multiplicand, const double multiplier)
|
||||
inline void bgc_fp64_vector3_multiply_by_real(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* multiplicand, const double multiplier)
|
||||
{
|
||||
product->x1 = multiplicand->x1 * multiplier;
|
||||
product->x2 = multiplicand->x2 * multiplier;
|
||||
|
|
@ -224,14 +224,26 @@ inline void bgc_fp64_vector3_multiply(BGC_FP64_Vector3* product, const BGC_FP64_
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_fp32_vector3_divide(BGC_FP32_Vector3* quotient, const BGC_FP32_Vector3* dividend, const float divisor)
|
||||
inline int bgc_fp32_vector3_divide_by_real(BGC_FP32_Vector3* quotient, const BGC_FP32_Vector3* dividend, const float divisor)
|
||||
{
|
||||
bgc_fp32_vector3_multiply(quotient, dividend, 1.0f / divisor);
|
||||
if (bgc_fp32_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_vector3_multiply_by_real(quotient, dividend, 1.0f / divisor);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_vector3_divide(BGC_FP64_Vector3* quotient, const BGC_FP64_Vector3* dividend, const double divisor)
|
||||
inline int bgc_fp64_vector3_divide_by_real(BGC_FP64_Vector3* quotient, const BGC_FP64_Vector3* dividend, const double divisor)
|
||||
{
|
||||
bgc_fp64_vector3_multiply(quotient, dividend, 1.0 / divisor);
|
||||
if (bgc_fp64_is_zero(divisor) || isnan(divisor)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_vector3_multiply_by_real(quotient, dividend, 1.0 / divisor);
|
||||
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// ================== Average2 ================== //
|
||||
|
|
@ -322,12 +334,12 @@ inline int bgc_fp32_vector3_normalize(BGC_FP32_Vector3* vector)
|
|||
{
|
||||
const float square_modulus = bgc_fp32_vector3_get_square_modulus(vector);
|
||||
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
return 1;
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return 0;
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
const float multiplier = sqrtf(1.0f / square_modulus);
|
||||
|
|
@ -336,19 +348,19 @@ inline int bgc_fp32_vector3_normalize(BGC_FP32_Vector3* vector)
|
|||
vector->x2 *= multiplier;
|
||||
vector->x3 *= multiplier;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_vector3_normalize(BGC_FP64_Vector3* vector)
|
||||
{
|
||||
const double square_modulus = bgc_fp64_vector3_get_square_modulus(vector);
|
||||
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
return 1;
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
return 0;
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
const double multiplier = sqrt(1.0 / square_modulus);
|
||||
|
|
@ -357,43 +369,43 @@ inline int bgc_fp64_vector3_normalize(BGC_FP64_Vector3* vector)
|
|||
vector->x2 *= multiplier;
|
||||
vector->x3 *= multiplier;
|
||||
|
||||
return 1;
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp32_vector3_get_normalized(BGC_FP32_Vector3* normalized, const BGC_FP32_Vector3* vector)
|
||||
{
|
||||
const float square_modulus = bgc_fp32_vector3_get_square_modulus(vector);
|
||||
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
bgc_fp32_vector3_copy(normalized, vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
bgc_fp32_vector3_reset(normalized);
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp32_vector3_multiply(normalized, vector, sqrtf(1.0f / square_modulus));
|
||||
return 1;
|
||||
if (bgc_fp32_is_square_unit(square_modulus)) {
|
||||
bgc_fp32_vector3_copy(normalized, vector);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
bgc_fp32_vector3_multiply_by_real(normalized, vector, sqrtf(1.0f / square_modulus));
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
inline int bgc_fp64_vector3_get_normalized(BGC_FP64_Vector3* normalized, const BGC_FP64_Vector3* vector)
|
||||
{
|
||||
const double square_modulus = bgc_fp64_vector3_get_square_modulus(vector);
|
||||
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
bgc_fp64_vector3_copy(normalized, vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
|
||||
bgc_fp64_vector3_reset(normalized);
|
||||
return 0;
|
||||
return BGC_FAILURE;
|
||||
}
|
||||
|
||||
bgc_fp64_vector3_multiply(normalized, vector, sqrt(1.0 / square_modulus));
|
||||
return 1;
|
||||
if (bgc_fp64_is_square_unit(square_modulus)) {
|
||||
bgc_fp64_vector3_copy(normalized, vector);
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
bgc_fp64_vector3_multiply_by_real(normalized, vector, sqrt(1.0 / square_modulus));
|
||||
return BGC_SUCCESS;
|
||||
}
|
||||
|
||||
// =============== Scalar Product =============== //
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue