1214152Sed/* This file is distributed under the University of Illinois Open Source 2214152Sed * License. See LICENSE.TXT for details. 3214152Sed */ 4214152Sed 5214152Sed/* long double __floatditf(long long x); */ 6214152Sed/* This file implements the PowerPC long long -> long double conversion */ 7214152Sed 8214152Sed#include "DD.h" 9214152Sed 10214152Sedlong double __floatditf(int64_t a) { 11214152Sed 12214152Sed static const double twop32 = 0x1.0p32; 13214152Sed static const double twop52 = 0x1.0p52; 14214152Sed 15214152Sed doublebits low = { .d = twop52 }; 16214152Sed low.x |= a & UINT64_C(0x00000000ffffffff); /* 0x1.0p52 + low 32 bits of a. */ 17214152Sed 18214152Sed const double high_addend = (double)((int32_t)(a >> 32))*twop32 - twop52; 19214152Sed 20214152Sed /* At this point, we have two double precision numbers 21214152Sed * high_addend and low.d, and we wish to return their sum 22214152Sed * as a canonicalized long double: 23214152Sed */ 24214152Sed 25214152Sed /* This implementation sets the inexact flag spuriously. 26214152Sed * This could be avoided, but at some substantial cost. 27214152Sed */ 28214152Sed 29214152Sed DD result; 30214152Sed 31214152Sed result.s.hi = high_addend + low.d; 32214152Sed result.s.lo = (high_addend - result.s.hi) + low.d; 33214152Sed 34214152Sed return result.ld; 35214152Sed 36214152Sed} 37