yading@11
|
1 /*
|
yading@11
|
2 * Copyright (c) 2011 Mans Rullgard
|
yading@11
|
3 *
|
yading@11
|
4 * This file is part of Libav.
|
yading@11
|
5 *
|
yading@11
|
6 * Libav is free software; you can redistribute it and/or
|
yading@11
|
7 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
8 * License as published by the Free Software Foundation; either
|
yading@11
|
9 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
10 *
|
yading@11
|
11 * Libav is distributed in the hope that it will be useful,
|
yading@11
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
14 * Lesser General Public License for more details.
|
yading@11
|
15 *
|
yading@11
|
16 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
17 * License along with Libav; if not, write to the Free Software
|
yading@11
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
19 */
|
yading@11
|
20
|
yading@11
|
21 #ifndef AVUTIL_INTFLOAT_H
|
yading@11
|
22 #define AVUTIL_INTFLOAT_H
|
yading@11
|
23
|
yading@11
|
24 #include <stdint.h>
|
yading@11
|
25 #include "attributes.h"
|
yading@11
|
26
|
yading@11
|
27 union av_intfloat32 {
|
yading@11
|
28 uint32_t i;
|
yading@11
|
29 float f;
|
yading@11
|
30 };
|
yading@11
|
31
|
yading@11
|
32 union av_intfloat64 {
|
yading@11
|
33 uint64_t i;
|
yading@11
|
34 double f;
|
yading@11
|
35 };
|
yading@11
|
36
|
yading@11
|
37 /**
|
yading@11
|
38 * Reinterpret a 32-bit integer as a float.
|
yading@11
|
39 */
|
yading@11
|
40 static av_always_inline float av_int2float(uint32_t i)
|
yading@11
|
41 {
|
yading@11
|
42 union av_intfloat32 v;
|
yading@11
|
43 v.i = i;
|
yading@11
|
44 return v.f;
|
yading@11
|
45 }
|
yading@11
|
46
|
yading@11
|
47 /**
|
yading@11
|
48 * Reinterpret a float as a 32-bit integer.
|
yading@11
|
49 */
|
yading@11
|
50 static av_always_inline uint32_t av_float2int(float f)
|
yading@11
|
51 {
|
yading@11
|
52 union av_intfloat32 v;
|
yading@11
|
53 v.f = f;
|
yading@11
|
54 return v.i;
|
yading@11
|
55 }
|
yading@11
|
56
|
yading@11
|
57 /**
|
yading@11
|
58 * Reinterpret a 64-bit integer as a double.
|
yading@11
|
59 */
|
yading@11
|
60 static av_always_inline double av_int2double(uint64_t i)
|
yading@11
|
61 {
|
yading@11
|
62 union av_intfloat64 v;
|
yading@11
|
63 v.i = i;
|
yading@11
|
64 return v.f;
|
yading@11
|
65 }
|
yading@11
|
66
|
yading@11
|
67 /**
|
yading@11
|
68 * Reinterpret a double as a 64-bit integer.
|
yading@11
|
69 */
|
yading@11
|
70 static av_always_inline uint64_t av_double2int(double f)
|
yading@11
|
71 {
|
yading@11
|
72 union av_intfloat64 v;
|
yading@11
|
73 v.f = f;
|
yading@11
|
74 return v.i;
|
yading@11
|
75 }
|
yading@11
|
76
|
yading@11
|
77 #endif /* AVUTIL_INTFLOAT_H */
|