#include <math.h>#include "convert_numeric.h"Go to the source code of this file.
| #define FLOATFORMAT_CHAR_BIT 8 |
Definition at line 77 of file convert_numeric.c.
Referenced by EXTRACTOR_common_floatformat_from_double(), get_field(), and put_field().
| #define INFINITY (1.0 / 0.0) |
Definition at line 47 of file convert_numeric.c.
Referenced by EXTRACTOR_common_floatformat_to_double().
| #define min | ( | a, | |||
| b | ) | ((a) < (b) ? (a) : (b)) |
Definition at line 254 of file convert_numeric.c.
Referenced by adx_encode(), av_set_number(), avfilter_poll_frame(), dering(), dering_altivec(), direct_search(), dnxhd_encode_rdo(), do_a_deblock_C(), EXTRACTOR_common_floatformat_to_double(), get_field(), get_new_centroids(), h264_deblock_q1(), isVertMinMaxOk_C(), pred_intra_mode(), put_field(), qdm2_decode_fft_packets(), readBuf(), and x8_loop_filter().
| #define NAN (0.0 / 0.0) |
Definition at line 55 of file convert_numeric.c.
Referenced by eval_expr(), EXTRACTOR_common_floatformat_to_double(), and ff_eval2().
| void EXTRACTOR_common_floatformat_from_double | ( | const struct EXTRACTOR_floatformat * | fmt, | |
| const double * | from, | |||
| void * | to | |||
| ) |
Definition at line 464 of file convert_numeric.c.
References EXTRACTOR_floatformat::byteorder, EXTRACTOR_floatformat::exp_bias, EXTRACTOR_floatformat::exp_len, EXTRACTOR_floatformat::exp_nan, EXTRACTOR_floatformat::exp_start, FLOATFORMAT_CHAR_BIT, floatformat_intbit_no, EXTRACTOR_floatformat::intbit, EXTRACTOR_floatformat::man_len, EXTRACTOR_floatformat::man_start, put_field(), EXTRACTOR_floatformat::sign_start, and EXTRACTOR_floatformat::totalsize.
00466 { 00467 double dfrom; 00468 int exponent; 00469 double mant; 00470 unsigned int mant_bits, mant_off; 00471 int mant_bits_left; 00472 unsigned char *uto = (unsigned char *) to; 00473 00474 dfrom = *from; 00475 memset (uto, 0, fmt->totalsize / FLOATFORMAT_CHAR_BIT); 00476 00477 /* If negative, set the sign bit. */ 00478 if (dfrom < 0) 00479 { 00480 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1); 00481 dfrom = -dfrom; 00482 } 00483 00484 if (dfrom == 0) 00485 { 00486 /* 0.0. */ 00487 return; 00488 } 00489 00490 if (dfrom != dfrom) 00491 { 00492 /* NaN. */ 00493 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, 00494 fmt->exp_len, fmt->exp_nan); 00495 /* Be sure it's not infinity, but NaN value is irrelevant. */ 00496 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start, 00497 32, 1); 00498 return; 00499 } 00500 00501 if (dfrom + dfrom == dfrom) 00502 { 00503 /* This can only happen for an infinite value (or zero, which we 00504 already handled above). */ 00505 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, 00506 fmt->exp_len, fmt->exp_nan); 00507 return; 00508 } 00509 00510 mant = frexp (dfrom, &exponent); 00511 if (exponent + fmt->exp_bias - 1 > 0) 00512 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, 00513 fmt->exp_len, exponent + fmt->exp_bias - 1); 00514 else 00515 { 00516 /* Handle a denormalized number. FIXME: What should we do for 00517 non-IEEE formats? */ 00518 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, 00519 fmt->exp_len, 0); 00520 mant = ldexp (mant, exponent + fmt->exp_bias - 1); 00521 } 00522 00523 mant_bits_left = fmt->man_len; 00524 mant_off = fmt->man_start; 00525 while (mant_bits_left > 0) 00526 { 00527 unsigned long mant_long; 00528 mant_bits = mant_bits_left < 32 ? mant_bits_left : 32; 00529 00530 mant *= 4294967296.0; 00531 mant_long = (unsigned long)mant; 00532 mant -= mant_long; 00533 00534 /* If the integer bit is implicit, and we are not creating a 00535 denormalized number, then we need to discard it. */ 00536 if ((unsigned int) mant_bits_left == fmt->man_len 00537 && fmt->intbit == floatformat_intbit_no 00538 && exponent + fmt->exp_bias - 1 > 0) 00539 { 00540 mant_long &= 0x7fffffff; 00541 mant_bits -= 1; 00542 } 00543 else if (mant_bits < 32) 00544 { 00545 /* The bits we want are in the most significant MANT_BITS bits of 00546 mant_long. Move them to the least significant. */ 00547 mant_long >>= 32 - mant_bits; 00548 } 00549 00550 put_field (uto, fmt->byteorder, fmt->totalsize, 00551 mant_off, mant_bits, mant_long); 00552 mant_off += mant_bits; 00553 mant_bits_left -= mant_bits; 00554 } 00555 }
| int EXTRACTOR_common_floatformat_is_valid | ( | const struct EXTRACTOR_floatformat * | fmt, | |
| const void * | from | |||
| ) |
Definition at line 560 of file convert_numeric.c.
References EXTRACTOR_floatformat::is_valid.
00561 { 00562 return fmt->is_valid (fmt, from); 00563 }
| void EXTRACTOR_common_floatformat_to_double | ( | const struct EXTRACTOR_floatformat * | fmt, | |
| const void * | from, | |||
| double * | to | |||
| ) |
Definition at line 302 of file convert_numeric.c.
References EXTRACTOR_floatformat::byteorder, EXTRACTOR_floatformat::exp_bias, EXTRACTOR_floatformat::exp_len, EXTRACTOR_floatformat::exp_nan, EXTRACTOR_floatformat::exp_start, floatformat_intbit_no, get_field(), INFINITY, EXTRACTOR_floatformat::intbit, EXTRACTOR_floatformat::man_len, EXTRACTOR_floatformat::man_start, min, NAN, EXTRACTOR_floatformat::sign_start, and EXTRACTOR_floatformat::totalsize.
Referenced by readDouble().
00304 { 00305 const unsigned char *ufrom = (const unsigned char *) from; 00306 double dto; 00307 long exponent; 00308 unsigned long mant; 00309 unsigned int mant_bits, mant_off; 00310 int mant_bits_left; 00311 int special_exponent; /* It's a NaN, denorm or zero */ 00312 00313 exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize, 00314 fmt->exp_start, fmt->exp_len); 00315 00316 /* If the exponent indicates a NaN, we don't have information to 00317 decide what to do. So we handle it like IEEE, except that we 00318 don't try to preserve the type of NaN. FIXME. */ 00319 if ((unsigned long) exponent == fmt->exp_nan) 00320 { 00321 int nan; 00322 00323 mant_off = fmt->man_start; 00324 mant_bits_left = fmt->man_len; 00325 nan = 0; 00326 while (mant_bits_left > 0) 00327 { 00328 mant_bits = min (mant_bits_left, 32); 00329 00330 if (get_field (ufrom, fmt->byteorder, fmt->totalsize, 00331 mant_off, mant_bits) != 0) 00332 { 00333 /* This is a NaN. */ 00334 nan = 1; 00335 break; 00336 } 00337 00338 mant_off += mant_bits; 00339 mant_bits_left -= mant_bits; 00340 } 00341 00342 /* On certain systems (such as GNU/Linux), the use of the 00343 INFINITY macro below may generate a warning that can not be 00344 silenced due to a bug in GCC (PR preprocessor/11931). The 00345 preprocessor fails to recognise the __extension__ keyword in 00346 conjunction with the GNU/C99 extension for hexadecimal 00347 floating point constants and will issue a warning when 00348 compiling with -pedantic. */ 00349 if (nan) 00350 dto = NAN; 00351 else 00352 dto = INFINITY; 00353 00354 if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1)) 00355 dto = -dto; 00356 00357 *to = dto; 00358 00359 return; 00360 } 00361 00362 mant_bits_left = fmt->man_len; 00363 mant_off = fmt->man_start; 00364 dto = 0.0; 00365 00366 special_exponent = exponent == 0 || (unsigned long) exponent == fmt->exp_nan; 00367 00368 /* Don't bias zero's, denorms or NaNs. */ 00369 if (!special_exponent) 00370 exponent -= fmt->exp_bias; 00371 00372 /* Build the result algebraically. Might go infinite, underflow, etc; 00373 who cares. */ 00374 00375 /* If this format uses a hidden bit, explicitly add it in now. Otherwise, 00376 increment the exponent by one to account for the integer bit. */ 00377 00378 if (!special_exponent) 00379 { 00380 if (fmt->intbit == floatformat_intbit_no) 00381 dto = ldexp (1.0, exponent); 00382 else 00383 exponent++; 00384 } 00385 00386 while (mant_bits_left > 0) 00387 { 00388 mant_bits = min (mant_bits_left, 32); 00389 00390 mant = get_field (ufrom, fmt->byteorder, fmt->totalsize, 00391 mant_off, mant_bits); 00392 00393 /* Handle denormalized numbers. FIXME: What should we do for 00394 non-IEEE formats? */ 00395 if (special_exponent && exponent == 0 && mant != 0) 00396 dto += ldexp ((double)mant, 00397 (- fmt->exp_bias 00398 - mant_bits 00399 - (mant_off - fmt->man_start) 00400 + 1)); 00401 else 00402 dto += ldexp ((double)mant, exponent - mant_bits); 00403 if (exponent != 0) 00404 exponent -= mant_bits; 00405 mant_off += mant_bits; 00406 mant_bits_left -= mant_bits; 00407 } 00408 00409 /* Negate it if negative. */ 00410 if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1)) 00411 dto = -dto; 00412 *to = dto; 00413 }
| static int floatformat_always_valid | ( | const struct EXTRACTOR_floatformat * | fmt, | |
| const void * | from | |||
| ) | [static] |
| static int floatformat_i387_ext_is_valid | ( | const struct EXTRACTOR_floatformat * | fmt, | |
| const void * | from | |||
| ) | [static] |
Definition at line 148 of file convert_numeric.c.
References EXTRACTOR_floatformat::byteorder, EXTRACTOR_floatformat::exp_len, EXTRACTOR_floatformat::exp_start, get_field(), EXTRACTOR_floatformat::man_start, and EXTRACTOR_floatformat::totalsize.
00149 { 00150 /* In the i387 double-extended format, if the exponent is all ones, 00151 then the integer bit must be set. If the exponent is neither 0 00152 nor ~0, the intbit must also be set. Only if the exponent is 00153 zero can it be zero, and then it must be zero. */ 00154 unsigned long exponent, int_bit; 00155 const unsigned char *ufrom = (const unsigned char *) from; 00156 00157 exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize, 00158 fmt->exp_start, fmt->exp_len); 00159 int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize, 00160 fmt->man_start, 1); 00161 00162 if ((exponent == 0) != (int_bit == 0)) 00163 return 0; 00164 else 00165 return 1; 00166 }
| static unsigned long get_field | ( | const unsigned char * | , | |
| enum | EXTRACTOR_floatformat_byteorders, | |||
| unsigned | int, | |||
| unsigned | int, | |||
| unsigned | int | |||
| ) | [static] |
Definition at line 260 of file convert_numeric.c.
References bits, FLOATFORMAT_CHAR_BIT, floatformat_little, mask, and min.
Referenced by EXTRACTOR_common_floatformat_to_double(), and floatformat_i387_ext_is_valid().
00262 { 00263 unsigned long result = 0; 00264 unsigned int cur_byte; 00265 int lo_bit, hi_bit, cur_bitshift = 0; 00266 int nextbyte = (order == floatformat_little) ? 1 : -1; 00267 00268 /* Start is in big-endian bit order! Fix that first. */ 00269 start = total_len - (start + len); 00270 00271 /* Start at the least significant part of the field. */ 00272 if (order == floatformat_little) 00273 cur_byte = start / FLOATFORMAT_CHAR_BIT; 00274 else 00275 cur_byte = (total_len - start - 1) / FLOATFORMAT_CHAR_BIT; 00276 00277 lo_bit = start % FLOATFORMAT_CHAR_BIT; 00278 hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT); 00279 00280 do 00281 { 00282 unsigned int shifted = *(data + cur_byte) >> lo_bit; 00283 unsigned int bits = hi_bit - lo_bit; 00284 unsigned int mask = (1 << bits) - 1; 00285 result |= (shifted & mask) << cur_bitshift; 00286 len -= bits; 00287 cur_bitshift += bits; 00288 cur_byte += nextbyte; 00289 lo_bit = 0; 00290 hi_bit = min (len, FLOATFORMAT_CHAR_BIT); 00291 } 00292 while (len != 0); 00293 00294 return result; 00295 }
| static void put_field | ( | unsigned char * | , | |
| enum | EXTRACTOR_floatformat_byteorders, | |||
| unsigned | int, | |||
| unsigned | int, | |||
| unsigned | int, | |||
| unsigned | long | |||
| ) | [static] |
Definition at line 424 of file convert_numeric.c.
References bits, FLOATFORMAT_CHAR_BIT, floatformat_little, mask, and min.
Referenced by EXTRACTOR_common_floatformat_from_double().
00427 { 00428 unsigned int cur_byte; 00429 int lo_bit, hi_bit; 00430 int nextbyte = (order == floatformat_little) ? 1 : -1; 00431 00432 /* Start is in big-endian bit order! Fix that first. */ 00433 start = total_len - (start + len); 00434 00435 /* Start at the least significant part of the field. */ 00436 if (order == floatformat_little) 00437 cur_byte = start / FLOATFORMAT_CHAR_BIT; 00438 else 00439 cur_byte = (total_len - start - 1) / FLOATFORMAT_CHAR_BIT; 00440 00441 lo_bit = start % FLOATFORMAT_CHAR_BIT; 00442 hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT); 00443 00444 do 00445 { 00446 unsigned char *byte_ptr = data + cur_byte; 00447 unsigned int bits = hi_bit - lo_bit; 00448 unsigned int mask = ((1 << bits) - 1) << lo_bit; 00449 *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask); 00450 stuff_to_put >>= bits; 00451 len -= bits; 00452 cur_byte += nextbyte; 00453 lo_bit = 0; 00454 hi_bit = min (len, FLOATFORMAT_CHAR_BIT); 00455 } 00456 while (len != 0); 00457 }
Initial value:
{
floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
floatformat_intbit_yes,
"floatformat_arm_ext_big",
floatformat_always_valid
}
Definition at line 207 of file convert_numeric.c.
Initial value:
{
floatformat_littlebyte_bigword, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
floatformat_intbit_yes,
"floatformat_arm_ext_littlebyte_bigword",
floatformat_always_valid
}
Definition at line 215 of file convert_numeric.c.
Initial value:
{
floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
floatformat_intbit_yes,
"floatformat_i387_ext",
floatformat_i387_ext_is_valid
}
Definition at line 168 of file convert_numeric.c.
Initial value:
{
floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64,
floatformat_intbit_yes,
"floatformat_i960_ext",
floatformat_always_valid
}
Definition at line 183 of file convert_numeric.c.
Initial value:
{
floatformat_big, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
floatformat_intbit_no,
"floatformat_ia64_quad_big",
floatformat_always_valid
}
Definition at line 237 of file convert_numeric.c.
Initial value:
{
floatformat_little, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
floatformat_intbit_no,
"floatformat_ia64_quad_little",
floatformat_always_valid
}
Definition at line 244 of file convert_numeric.c.
Initial value:
{
floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
floatformat_intbit_yes,
"floatformat_ia64_spill_big",
floatformat_always_valid
}
Definition at line 223 of file convert_numeric.c.
Initial value:
{
floatformat_little, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
floatformat_intbit_yes,
"floatformat_ia64_spill_little",
floatformat_always_valid
}
Definition at line 230 of file convert_numeric.c.
Initial value:
{
floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52,
floatformat_intbit_no,
"floatformat_ieee_double_big",
floatformat_always_valid
}
Definition at line 94 of file convert_numeric.c.
Referenced by readDouble().
Initial value:
{
floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52,
floatformat_intbit_no,
"floatformat_ieee_double_little",
floatformat_always_valid
}
Definition at line 101 of file convert_numeric.c.
Initial value:
{
floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52,
floatformat_intbit_no,
"floatformat_ieee_double_littlebyte_bigword",
floatformat_always_valid
}
Definition at line 112 of file convert_numeric.c.
Initial value:
{
floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23,
floatformat_intbit_no,
"floatformat_ieee_single_big",
floatformat_always_valid
}
Definition at line 80 of file convert_numeric.c.
Initial value:
{
floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23,
floatformat_intbit_no,
"floatformat_ieee_single_little",
floatformat_always_valid
}
Definition at line 87 of file convert_numeric.c.
Initial value:
{
floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64,
floatformat_intbit_yes,
"floatformat_m68881_ext",
floatformat_always_valid
}
Definition at line 175 of file convert_numeric.c.
Initial value:
{
floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
floatformat_intbit_yes,
"floatformat_m88110_ext",
floatformat_always_valid
}
Definition at line 191 of file convert_numeric.c.
Initial value:
{
floatformat_big,128, 0, 1, 11, 0x3ff, 0x7ff, 12, 52,
floatformat_intbit_no,
"floatformat_m88110_ext_harris",
floatformat_always_valid
}
Definition at line 198 of file convert_numeric.c.
Initial value:
{
floatformat_vax, 64, 0, 1, 8, 129, 0, 9, 55,
floatformat_intbit_no,
"floatformat_vax_d",
floatformat_always_valid
}
Definition at line 129 of file convert_numeric.c.
Initial value:
{
floatformat_vax, 32, 0, 1, 8, 129, 0, 9, 23,
floatformat_intbit_no,
"floatformat_vax_f",
floatformat_always_valid
}
Definition at line 122 of file convert_numeric.c.
Initial value:
{
floatformat_vax, 64, 0, 1, 11, 1025, 0, 12, 52,
floatformat_intbit_no,
"floatformat_vax_g",
floatformat_always_valid
}
Definition at line 136 of file convert_numeric.c.
1.5.1