From f966ef70fcacc5777e930014746cf634c0974f29 Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Tue, 5 Jun 2001 02:03:11 +0000 Subject: [PATCH] minor FP tweaks --- src/libFLAC/fixed.c | 30 +++++++++++++++--------------- src/libFLAC/lpc.c | 6 +++--- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libFLAC/fixed.c b/src/libFLAC/fixed.c index 8fd6a5d..f7b423b 100644 --- a/src/libFLAC/fixed.c +++ b/src/libFLAC/fixed.c @@ -65,11 +65,11 @@ unsigned FLAC__fixed_compute_best_predictor(const int32 data[], unsigned data_le else order = 4; - residual_bits_per_sample[0] = (real)((data_len > 0 && total_error_0 > 0) ? log(M_LN2 * (real)total_error_0 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (real)((data_len > 0 && total_error_1 > 0) ? log(M_LN2 * (real)total_error_1 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (real)((data_len > 0 && total_error_2 > 0) ? log(M_LN2 * (real)total_error_2 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (real)((data_len > 0 && total_error_3 > 0) ? log(M_LN2 * (real)total_error_3 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (real)((data_len > 0 && total_error_4 > 0) ? log(M_LN2 * (real)total_error_4 / (real) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[0] = (real)((data_len > 0 && total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[1] = (real)((data_len > 0 && total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[2] = (real)((data_len > 0 && total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[3] = (real)((data_len > 0 && total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[4] = (real)((data_len > 0 && total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double) data_len) / M_LN2 : 0.0); return order; } @@ -112,17 +112,17 @@ unsigned FLAC__fixed_compute_best_predictor_slow(const int32 data[], unsigned da /* signal, so we use it directly to compute E(|x|) */ #ifdef _MSC_VER /* with VC++ you have to spoon feed it the casting */ - residual_bits_per_sample[0] = (real)((data_len > 0 && total_error_0 > 0) ? log(M_LN2 * (real)(int64)total_error_0 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (real)((data_len > 0 && total_error_1 > 0) ? log(M_LN2 * (real)(int64)total_error_1 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (real)((data_len > 0 && total_error_2 > 0) ? log(M_LN2 * (real)(int64)total_error_2 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (real)((data_len > 0 && total_error_3 > 0) ? log(M_LN2 * (real)(int64)total_error_3 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (real)((data_len > 0 && total_error_4 > 0) ? log(M_LN2 * (real)(int64)total_error_4 / (real) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[0] = (real)((data_len > 0 && total_error_0 > 0) ? log(M_LN2 * (double)(int64)total_error_0 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[1] = (real)((data_len > 0 && total_error_1 > 0) ? log(M_LN2 * (double)(int64)total_error_1 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[2] = (real)((data_len > 0 && total_error_2 > 0) ? log(M_LN2 * (double)(int64)total_error_2 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[3] = (real)((data_len > 0 && total_error_3 > 0) ? log(M_LN2 * (double)(int64)total_error_3 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[4] = (real)((data_len > 0 && total_error_4 > 0) ? log(M_LN2 * (double)(int64)total_error_4 / (double) data_len) / M_LN2 : 0.0); #else - residual_bits_per_sample[0] = (real)((data_len > 0 && total_error_0 > 0) ? log(M_LN2 * (real)total_error_0 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (real)((data_len > 0 && total_error_1 > 0) ? log(M_LN2 * (real)total_error_1 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (real)((data_len > 0 && total_error_2 > 0) ? log(M_LN2 * (real)total_error_2 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (real)((data_len > 0 && total_error_3 > 0) ? log(M_LN2 * (real)total_error_3 / (real) data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (real)((data_len > 0 && total_error_4 > 0) ? log(M_LN2 * (real)total_error_4 / (real) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[0] = (real)((data_len > 0 && total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[1] = (real)((data_len > 0 && total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[2] = (real)((data_len > 0 && total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[3] = (real)((data_len > 0 && total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double) data_len) / M_LN2 : 0.0); + residual_bits_per_sample[4] = (real)((data_len > 0 && total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double) data_len) / M_LN2 : 0.0); #endif return order; diff --git a/src/libFLAC/lpc.c b/src/libFLAC/lpc.c index ddca21e..06d6808 100644 --- a/src/libFLAC/lpc.c +++ b/src/libFLAC/lpc.c @@ -112,7 +112,7 @@ void FLAC__lpc_compute_lp_coefficients(const real autoc[], unsigned max_order, r int FLAC__lpc_quantize_coefficients(const real lp_coeff[], unsigned order, unsigned precision, unsigned bits_per_sample, int32 qlp_coeff[], int *shift) { unsigned i; - real d, cmax = -1e10; + real d, cmax = -1e32; FLAC__ASSERT(bits_per_sample > 0); FLAC__ASSERT(bits_per_sample <= sizeof(int32)*8); @@ -262,7 +262,7 @@ real FLAC__lpc_compute_expected_bits_per_residual_sample(real lpc_error, unsigne return 0.0; } else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate float resolution */ - return 1e10; + return 1e32; } else { return 0.0; @@ -279,7 +279,7 @@ real FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(real l return 0.0; } else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate float resolution */ - return 1e10; + return 1e32; } else { return 0.0; -- 2.7.4