101e04c3fSmrg/************************************************************************** 201e04c3fSmrg * 301e04c3fSmrg * Copyright © 2016 Intel Corporation 401e04c3fSmrg * All Rights Reserved. 501e04c3fSmrg * 601e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 701e04c3fSmrg * copy of this software and associated documentation files (the 801e04c3fSmrg * "Software"), to deal in the Software without restriction, including 901e04c3fSmrg * without limitation the rights to use, copy, modify, merge, publish, 1001e04c3fSmrg * distribute, sub license, and/or sell copies of the Software, and to 1101e04c3fSmrg * permit persons to whom the Software is furnished to do so, subject to 1201e04c3fSmrg * the following conditions: 1301e04c3fSmrg * 1401e04c3fSmrg * The above copyright notice and this permission notice (including the 1501e04c3fSmrg * next paragraph) shall be included in all copies or substantial portions 1601e04c3fSmrg * of the Software. 1701e04c3fSmrg * 1801e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1901e04c3fSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2001e04c3fSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 2101e04c3fSmrg * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 2201e04c3fSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 2301e04c3fSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 2401e04c3fSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2501e04c3fSmrg * 2601e04c3fSmrg **************************************************************************/ 2701e04c3fSmrg 2801e04c3fSmrg#ifndef U_BITCAST_H_ 2901e04c3fSmrg#define U_BITCAST_H_ 3001e04c3fSmrg 3101e04c3fSmrg#include <string.h> 327ec681f3Smrg#include <stdint.h> 3301e04c3fSmrg 3401e04c3fSmrg#include "c99_compat.h" 3501e04c3fSmrg 3601e04c3fSmrg#ifdef __cplusplus 3701e04c3fSmrgextern "C" { 3801e04c3fSmrg#endif 3901e04c3fSmrg 407ec681f3Smrgstatic inline uint32_t 4101e04c3fSmrgu_bitcast_f2u(float f) 4201e04c3fSmrg{ 4301e04c3fSmrg unsigned u; 4401e04c3fSmrg memcpy(&u, &f, sizeof(u)); 4501e04c3fSmrg return u; 4601e04c3fSmrg} 4701e04c3fSmrg 487ec681f3Smrgstatic inline uint64_t 497ec681f3Smrgu_bitcast_d2u(double d) 507ec681f3Smrg{ 517ec681f3Smrg uint64_t u; 527ec681f3Smrg memcpy(&u, &d, sizeof(u)); 537ec681f3Smrg return u; 547ec681f3Smrg} 557ec681f3Smrg 5601e04c3fSmrgstatic inline float 577ec681f3Smrgu_bitcast_u2f(uint32_t u) 5801e04c3fSmrg{ 5901e04c3fSmrg float f; 6001e04c3fSmrg memcpy(&f, &u, sizeof(f)); 6101e04c3fSmrg return f; 6201e04c3fSmrg} 6301e04c3fSmrg 647ec681f3Smrgstatic inline double 657ec681f3Smrgu_bitcast_u2d(uint64_t u) 667ec681f3Smrg{ 677ec681f3Smrg double d; 687ec681f3Smrg memcpy(&d, &u, sizeof(d)); 697ec681f3Smrg return d; 707ec681f3Smrg} 717ec681f3Smrg 7201e04c3fSmrg#ifdef __cplusplus 7301e04c3fSmrg} 7401e04c3fSmrg#endif 7501e04c3fSmrg 7601e04c3fSmrg#endif /* U_BITCAST_H_ */ 77