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 = { .i = i }; 00043 return v.f; 00044 } 00045 00049 static av_always_inline uint32_t av_float2int(float f) 00050 { 00051 union av_intfloat32 v = { .f = f }; 00052 return v.i; 00053 } 00054 00058 static av_always_inline double av_int2double(uint64_t i) 00059 { 00060 union av_intfloat64 v = { .i = i }; 00061 return v.f; 00062 } 00063 00067 static av_always_inline uint64_t av_double2int(double f) 00068 { 00069 union av_intfloat64 v = { .f = f }; 00070 return v.i; 00071 } 00072 00073 #endif /* AVUTIL_INTFLOAT_H */