Упорядочивание проекта
This commit is contained in:
parent
0dcd9c0d4d
commit
89dfd7644b
32 changed files with 1730 additions and 1719 deletions
|
|
@ -142,23 +142,75 @@ inline void bgc_complex_convert_fp32_to_fp64(const BgcComplexFP32* source, BgcCo
|
|||
destination->imaginary = source->imaginary;
|
||||
}
|
||||
|
||||
// ================== Reverse =================== //
|
||||
// ================== Negative ================== //
|
||||
|
||||
inline void bgc_complex_reverse_fp32(const BgcComplexFP32* number, BgcComplexFP32* reverse)
|
||||
inline void bgc_complex_make_opposite_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
reverse->real = -number->real;
|
||||
reverse->imaginary = -number->imaginary;
|
||||
number->real = -number->real;
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_reverse_fp64(const BgcComplexFP64* number, BgcComplexFP64* reverse)
|
||||
inline void bgc_complex_make_opposite_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
reverse->real = -number->real;
|
||||
reverse->imaginary = -number->imaginary;
|
||||
number->real = -number->real;
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_opposite_fp32(const BgcComplexFP32* number, BgcComplexFP32* opposite)
|
||||
{
|
||||
opposite->real = -number->real;
|
||||
opposite->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_opposite_fp64(const BgcComplexFP64* number, BgcComplexFP64* opposite)
|
||||
{
|
||||
opposite->real = -number->real;
|
||||
opposite->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP32* normalized)
|
||||
inline int bgc_complex_normalize_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(number);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplicand = sqrtf(1.0f / square_modulus);
|
||||
|
||||
number->real *= multiplicand;
|
||||
number->imaginary *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_normalize_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(number);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplicand = sqrt(1.0 / square_modulus);
|
||||
|
||||
number->real *= multiplicand;
|
||||
number->imaginary *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_get_normalized_fp32(const BgcComplexFP32* number, BgcComplexFP32* normalized)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(number);
|
||||
|
||||
|
|
@ -169,6 +221,8 @@ inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP
|
|||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
normalized->real = 0.0f;
|
||||
normalized->imaginary = 0.0f;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +234,7 @@ inline int bgc_complex_normalize_fp32(const BgcComplexFP32* number, BgcComplexFP
|
|||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP64* normalized)
|
||||
inline int bgc_complex_get_normalized_fp64(const BgcComplexFP64* number, BgcComplexFP64* normalized)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(number);
|
||||
|
||||
|
|
@ -191,6 +245,8 @@ inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP
|
|||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
normalized->real = 0.0;
|
||||
normalized->imaginary = 0.0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -204,13 +260,23 @@ inline int bgc_complex_normalize_fp64(const BgcComplexFP64* number, BgcComplexFP
|
|||
|
||||
// ================= Conjugate ================== //
|
||||
|
||||
inline void bgc_complex_conjugate_fp32(const BgcComplexFP32* number, BgcComplexFP32* conjugate)
|
||||
inline void bgc_complex_conjugate_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_conjugate_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
number->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_conjugate_fp32(const BgcComplexFP32* number, BgcComplexFP32* conjugate)
|
||||
{
|
||||
conjugate->real = number->real;
|
||||
conjugate->imaginary = -number->imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_conjugate_fp64(const BgcComplexFP64* number, BgcComplexFP64* conjugate)
|
||||
inline void bgc_complex_get_conjugate_fp64(const BgcComplexFP64* number, BgcComplexFP64* conjugate)
|
||||
{
|
||||
conjugate->real = number->real;
|
||||
conjugate->imaginary = -number->imaginary;
|
||||
|
|
@ -218,7 +284,7 @@ inline void bgc_complex_conjugate_fp64(const BgcComplexFP64* number, BgcComplexF
|
|||
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline int bgc_complex_invert_fp32(const BgcComplexFP32* number, BgcComplexFP32* inverted)
|
||||
inline int bgc_complex_get_inverse_fp32(const BgcComplexFP32* number, BgcComplexFP32* inverse)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(number);
|
||||
|
||||
|
|
@ -228,13 +294,13 @@ inline int bgc_complex_invert_fp32(const BgcComplexFP32* number, BgcComplexFP32*
|
|||
|
||||
const float multiplicand = 1.0f / square_modulus;
|
||||
|
||||
inverted->real = number->real * multiplicand;
|
||||
inverted->imaginary = -number->imaginary * multiplicand;
|
||||
inverse->real = number->real * multiplicand;
|
||||
inverse->imaginary = -number->imaginary * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_invert_fp64(const BgcComplexFP64* number, BgcComplexFP64* inverted)
|
||||
inline int bgc_complex_get_inverse_fp64(const BgcComplexFP64* number, BgcComplexFP64* inverse)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(number);
|
||||
|
||||
|
|
@ -244,70 +310,20 @@ inline int bgc_complex_invert_fp64(const BgcComplexFP64* number, BgcComplexFP64*
|
|||
|
||||
const double multiplicand = 1.0 / square_modulus;
|
||||
|
||||
inverted->real = number->real * multiplicand;
|
||||
inverted->imaginary = -number->imaginary * multiplicand;
|
||||
inverse->real = number->real * multiplicand;
|
||||
inverse->imaginary = -number->imaginary * multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================ Get Product ================= //
|
||||
|
||||
inline void bgc_complex_get_product_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* result)
|
||||
inline int bgc_complex_invert_fp32(BgcComplexFP32* number)
|
||||
{
|
||||
const float real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const float imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
result->real = real;
|
||||
result->imaginary = imaginary;
|
||||
return bgc_complex_get_inverse_fp32(number, number);
|
||||
}
|
||||
|
||||
inline void bgc_complex_get_product_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* result)
|
||||
inline int bgc_complex_invert_fp64(BgcComplexFP64* number)
|
||||
{
|
||||
const double real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const double imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
result->real = real;
|
||||
result->imaginary = imaginary;
|
||||
}
|
||||
|
||||
// ================= Get Ratio ================== //
|
||||
|
||||
inline int bgc_complex_get_ratio_fp32(const BgcComplexFP32* divident, const BgcComplexFP32* divisor, BgcComplexFP32* quotient)
|
||||
{
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const float imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const float multiplier = 1.0f / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_complex_get_ratio_fp64(const BgcComplexFP64* divident, const BgcComplexFP64* divisor, BgcComplexFP64* quotient)
|
||||
{
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const double imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const double multiplier = 1.0 / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
return bgc_complex_get_inverse_fp64(number, number);
|
||||
}
|
||||
|
||||
// =============== Get Exponation =============== //
|
||||
|
|
@ -358,29 +374,35 @@ inline void bgc_complex_subtract_fp64(const BgcComplexFP64* minuend, const BgcCo
|
|||
difference->imaginary = minuend->imaginary - subtrahend->imaginary;
|
||||
}
|
||||
|
||||
// ============== Subtract scaled =============== //
|
||||
|
||||
inline void bgc_complex_subtract_scaled_fp32(const BgcComplexFP32* basic_number, const BgcComplexFP32* scalable_number, const float scale, BgcComplexFP32* difference)
|
||||
{
|
||||
difference->real = basic_number->real - scalable_number->real * scale;
|
||||
difference->imaginary = basic_number->imaginary - scalable_number->imaginary * scale;
|
||||
}
|
||||
|
||||
inline void bgc_complex_subtract_scaled_fp64(const BgcComplexFP64* basic_number, const BgcComplexFP64* scalable_number, const double scale, BgcComplexFP64* difference)
|
||||
{
|
||||
difference->real = basic_number->real - scalable_number->real * scale;
|
||||
difference->imaginary = basic_number->imaginary - scalable_number->imaginary * scale;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_complex_multiply_fp32(const BgcComplexFP32* multiplicand, const float multiplier, BgcComplexFP32* product)
|
||||
inline void bgc_complex_multiply_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, BgcComplexFP32* product)
|
||||
{
|
||||
const float real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const float imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
product->real = real;
|
||||
product->imaginary = imaginary;
|
||||
}
|
||||
|
||||
inline void bgc_complex_multiply_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, BgcComplexFP64* product)
|
||||
{
|
||||
const double real = number1->real * number2->real - number1->imaginary * number2->imaginary;
|
||||
const double imaginary = number1->real * number2->imaginary + number1->imaginary * number2->real;
|
||||
|
||||
product->real = real;
|
||||
product->imaginary = imaginary;
|
||||
}
|
||||
|
||||
// ============= Multiply By Number ============= //
|
||||
|
||||
inline void bgc_complex_multiply_by_number_fp32(const BgcComplexFP32* multiplicand, const float multiplier, BgcComplexFP32* product)
|
||||
{
|
||||
product->real = multiplicand->real * multiplier;
|
||||
product->imaginary = multiplicand->imaginary * multiplier;
|
||||
}
|
||||
|
||||
inline void bgc_complex_multiply_fp64(const BgcComplexFP64* multiplicand, const double multiplier, BgcComplexFP64* product)
|
||||
inline void bgc_complex_multiply_by_number_fp64(const BgcComplexFP64* multiplicand, const double multiplier, BgcComplexFP64* product)
|
||||
{
|
||||
product->real = multiplicand->real * multiplier;
|
||||
product->imaginary = multiplicand->imaginary * multiplier;
|
||||
|
|
@ -388,14 +410,54 @@ inline void bgc_complex_multiply_fp64(const BgcComplexFP64* multiplicand, const
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_complex_divide_fp32(const BgcComplexFP32* dividend, const float divisor, BgcComplexFP32* quotient)
|
||||
inline int bgc_complex_devide_fp32(const BgcComplexFP32* divident, const BgcComplexFP32* divisor, BgcComplexFP32* quotient)
|
||||
{
|
||||
bgc_complex_multiply_fp32(dividend, 1.0f / divisor, quotient);
|
||||
const float square_modulus = bgc_complex_get_square_modulus_fp32(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const float imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const float multiplier = 1.0f / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline void bgc_complex_divide_fp64(const BgcComplexFP64* dividend, const double divisor, BgcComplexFP64* quotient)
|
||||
inline int bgc_complex_devide_fp64(const BgcComplexFP64* divident, const BgcComplexFP64* divisor, BgcComplexFP64* quotient)
|
||||
{
|
||||
bgc_complex_multiply_fp64(dividend, 1.0 / divisor, quotient);
|
||||
const double square_modulus = bgc_complex_get_square_modulus_fp64(divisor);
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double real = divident->real * divisor->real + divident->imaginary * divisor->imaginary;
|
||||
const double imaginary = divident->imaginary * divisor->real - divident->real * divisor->imaginary;
|
||||
|
||||
const double multiplier = 1.0 / square_modulus;
|
||||
|
||||
quotient->real = real * multiplier;
|
||||
quotient->imaginary = imaginary * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ============== Divide By Number ============== //
|
||||
|
||||
inline void bgc_complex_divide_by_number_fp32(const BgcComplexFP32* dividend, const float divisor, BgcComplexFP32* quotient)
|
||||
{
|
||||
bgc_complex_multiply_by_number_fp32(dividend, 1.0f / divisor, quotient);
|
||||
}
|
||||
|
||||
inline void bgc_complex_divide_by_number_fp64(const BgcComplexFP64* dividend, const double divisor, BgcComplexFP64* quotient)
|
||||
{
|
||||
bgc_complex_multiply_by_number_fp64(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ================== Average2 ================== //
|
||||
|
|
@ -428,7 +490,7 @@ inline void bgc_complex_get_mean_of_three_fp64(const BgcComplexFP64* number1, co
|
|||
|
||||
// =================== Linear =================== //
|
||||
|
||||
inline void bgc_complex_interpolate_linearly_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation)
|
||||
inline void bgc_complex_interpolate_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2, const float phase, BgcComplexFP32* interpolation)
|
||||
{
|
||||
const float counterphase = 1.0f - phase;
|
||||
|
||||
|
|
@ -436,7 +498,7 @@ inline void bgc_complex_interpolate_linearly_fp32(const BgcComplexFP32* number1,
|
|||
interpolation->imaginary = number1->imaginary * counterphase + number2->imaginary * phase;
|
||||
}
|
||||
|
||||
inline void bgc_complex_interpolate_linearly_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const double phase, BgcComplexFP64* interpolation)
|
||||
inline void bgc_complex_interpolate_fp64(const BgcComplexFP64* number1, const BgcComplexFP64* number2, const double phase, BgcComplexFP64* interpolation)
|
||||
{
|
||||
const double counterphase = 1.0 - phase;
|
||||
|
||||
|
|
@ -444,54 +506,6 @@ inline void bgc_complex_interpolate_linearly_fp64(const BgcComplexFP64* number1,
|
|||
interpolation->imaginary = number1->imaginary * counterphase + number2->imaginary * phase;
|
||||
}
|
||||
|
||||
// ================== Minimal =================== //
|
||||
|
||||
inline void bgc_complex_minimize_fp32(const BgcComplexFP32* number, BgcComplexFP32* minimal)
|
||||
{
|
||||
if (number->real < minimal->real) {
|
||||
minimal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary < minimal->imaginary) {
|
||||
minimal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_complex_minimize_fp64(const BgcComplexFP64* number, BgcComplexFP64* minimal)
|
||||
{
|
||||
if (number->real < minimal->real) {
|
||||
minimal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary < minimal->imaginary) {
|
||||
minimal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
// ================== Maximal =================== //
|
||||
|
||||
inline void bgc_complex_maximize_fp32(const BgcComplexFP32* number, BgcComplexFP32* maximal)
|
||||
{
|
||||
if (number->real > maximal->real) {
|
||||
maximal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary > maximal->imaginary) {
|
||||
maximal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_complex_maximize_fp64(const BgcComplexFP64* number, BgcComplexFP64* maximal)
|
||||
{
|
||||
if (number->real > maximal->real) {
|
||||
maximal->real = number->real;
|
||||
}
|
||||
|
||||
if (number->imaginary > maximal->imaginary) {
|
||||
maximal->imaginary = number->imaginary;
|
||||
}
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
||||
inline int bgc_complex_are_close_fp32(const BgcComplexFP32* number1, const BgcComplexFP32* number2)
|
||||
|
|
@ -525,7 +539,7 @@ inline int bgc_complex_are_close_fp64(const BgcComplexFP64* number1, const BgcCo
|
|||
return square_distance <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
return square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP32 * square_modulus2;
|
||||
return square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus1 && square_distance <= BGC_SQUARE_EPSYLON_FP64 * square_modulus2;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue