00001 /* 00002 * Copyright (c) 2011 Mans Rullgard 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #ifndef AVUTIL_INTFLOAT_H 00022 #define AVUTIL_INTFLOAT_H 00023 00024 #include <stdint.h> 00025 #include "attributes.h" 00026 00027 union av_intfloat32 { 00028 uint32_t i; 00029 float f; 00030 }; 00031 00032 union av_intfloat64 { 00033 uint64_t i; 00034 double f; 00035 }; 00036 00040 static av_always_inline float av_int2float(uint32_t i) 00041 { 00042 union av_intfloat32 v; 00043 v.i = i; 00044 return v.f; 00045 } 00046 00050 static av_always_inline uint32_t av_float2int(float f) 00051 { 00052 union av_intfloat32 v; 00053 v.f = f; 00054 return v.i; 00055 } 00056 00060 static av_always_inline double av_int2double(uint64_t i) 00061 { 00062 union av_intfloat64 v; 00063 v.i = i; 00064 return v.f; 00065 } 00066 00070 static av_always_inline uint64_t av_double2int(double f) 00071 { 00072 union av_intfloat64 v; 00073 v.f = f; 00074 return v.i; 00075 } 00076 00077 #endif /* AVUTIL_INTFLOAT_H */