yading@11: /* yading@11: * Copyright (c) 2011 Mans Rullgard yading@11: * yading@11: * This file is part of Libav. yading@11: * yading@11: * Libav is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * Libav is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with Libav; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVUTIL_INTFLOAT_H yading@11: #define AVUTIL_INTFLOAT_H yading@11: yading@11: #include yading@11: #include "attributes.h" yading@11: yading@11: union av_intfloat32 { yading@11: uint32_t i; yading@11: float f; yading@11: }; yading@11: yading@11: union av_intfloat64 { yading@11: uint64_t i; yading@11: double f; yading@11: }; yading@11: yading@11: /** yading@11: * Reinterpret a 32-bit integer as a float. yading@11: */ yading@11: static av_always_inline float av_int2float(uint32_t i) yading@11: { yading@11: union av_intfloat32 v; yading@11: v.i = i; yading@11: return v.f; yading@11: } yading@11: yading@11: /** yading@11: * Reinterpret a float as a 32-bit integer. yading@11: */ yading@11: static av_always_inline uint32_t av_float2int(float f) yading@11: { yading@11: union av_intfloat32 v; yading@11: v.f = f; yading@11: return v.i; yading@11: } yading@11: yading@11: /** yading@11: * Reinterpret a 64-bit integer as a double. yading@11: */ yading@11: static av_always_inline double av_int2double(uint64_t i) yading@11: { yading@11: union av_intfloat64 v; yading@11: v.i = i; yading@11: return v.f; yading@11: } yading@11: yading@11: /** yading@11: * Reinterpret a double as a 64-bit integer. yading@11: */ yading@11: static av_always_inline uint64_t av_double2int(double f) yading@11: { yading@11: union av_intfloat64 v; yading@11: v.f = f; yading@11: return v.i; yading@11: } yading@11: yading@11: #endif /* AVUTIL_INTFLOAT_H */