Mercurial > libavutil.hg
annotate intfloat_readwrite.c @ 8:2dd915c714fa libavutil
fix for systems not defining PRIu64, not everyone knows C99.
author | mmu_man |
---|---|
date | Mon, 05 Dec 2005 23:14:55 +0000 |
parents | 89cdb3b541e2 |
children | ce8f9f4390c3 |
rev | line source |
---|---|
0
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
1 /* |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
2 * portable IEEE float/double read/write functions |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
3 * |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
4 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at> |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
5 * |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
6 * This library is free software; you can redistribute it and/or |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
8 * License as published by the Free Software Foundation; either |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
9 * version 2 of the License, or (at your option) any later version. |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
10 * |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
11 * This library is distributed in the hope that it will be useful, |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
14 * Lesser General Public License for more details. |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
15 * |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
17 * License along with this library; if not, write to the Free Software |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
19 */ |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
20 |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
21 /** |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
22 * @file intfloat_readwrite.c |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
23 * Portable IEEE float/double read/write functions. |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
24 */ |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
25 |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
26 #include "common.h" |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
27 |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
28 double av_int2dbl(int64_t v){ |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
29 if(v+v > 0xFFELLU<<52) |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
30 return 0.0/0.0; |
2 | 31 return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075); |
0
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
32 } |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
33 |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
34 float av_int2flt(int32_t v){ |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
35 if(v+v > 0xFF000000U) |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
36 return 0.0/0.0; |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
37 return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150); |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
38 } |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
39 |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
40 int64_t av_dbl2int(double d){ |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
41 int e; |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
42 if ( !d) return 0; |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
43 else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d); |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
44 d= frexp(d, &e); |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
45 return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53)); |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
46 } |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
47 |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
48 int32_t av_flt2int(float d){ |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
49 int e; |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
50 if ( !d) return 0; |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
51 else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d); |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
52 d= frexp(d, &e); |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
53 return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24)); |
ee8f44bb7c4d
libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff
changeset
|
54 } |