13 #include "cl_LF_impl.h"
17 double cl_double_approx (const cl_LF& x)
24 LF_decode(x, { return 0.0; }, sign=,exp=,ptr=,len=,);
25 // intDsize*len-DF_mant_len-1 Bits der Mantisse wegrunden:
26 // erste k := ceiling(DF_mant_len+2,intDsize) Digits nach manthi,mantlo holen:
27 var const int shiftcount = ceiling(DF_mant_len+2,intDsize)*intDsize-(DF_mant_len+1);
28 union { dfloat eksplicit; double machine_double; } u;
29 #if (cl_word_size==64)
30 var uint64 mant = get_max64_Dptr(DF_mant_len+2,ptr);
31 ptr = ptr mspop ceiling(DF_mant_len+2,intDsize);
32 if ( ((mant & bit(shiftcount-1)) ==0) // Bit 10 war 0 -> abrunden
33 || ( ((mant & (bit(shiftcount-1)-1)) ==0) // war 1, Bits 9..0 >0 -> aufrunden
34 && !test_loop_msp(ptr,len-ceiling(DF_mant_len+2,intDsize)) // weitere Bits /=0 -> aufrunden
36 && ((mant & bit(shiftcount)) ==0)
39 { mant = mant >> shiftcount; }
42 { mant = mant >> shiftcount;
44 if (mant >= bit(DF_mant_len+1))
45 // Überlauf durchs Runden
46 { mant = mant>>1; exp = exp+1; } // Mantisse rechts schieben
48 if (exp > (sintL)(DF_exp_high-DF_exp_mid))
50 ((sint64)sign & bit(63))
51 | ((uint64)(bit(DF_exp_len)-1) << DF_mant_len); // Infinity
54 if (exp < (sintL)(DF_exp_low-DF_exp_mid))
55 { u.eksplicit = ((sint64)sign & bit(63)); } // 0.0
58 ((sint64)sign & bit(63)) /* Vorzeichen */
59 | ((uint64)(exp+DF_exp_mid) << DF_mant_len) /* Exponent */
60 | ((uint64)mant & (bit(DF_mant_len)-1)); /* Mantisse */
63 var uint32 manthi = get_max32_Dptr(DF_mant_len+2-32,ptr);
64 var uint32 mantlo = get_32_Dptr(ptr mspop ceiling(DF_mant_len+2-32,intDsize));
65 ptr = ptr mspop ceiling(DF_mant_len+2,intDsize);
66 if ( ((mantlo & bit(shiftcount-1)) ==0) // Bit 10 war 0 -> abrunden
67 || ( ((mantlo & (bit(shiftcount-1)-1)) ==0) // war 1, Bits 9..0 >0 -> aufrunden
68 && !test_loop_msp(ptr,len-ceiling(DF_mant_len+2,intDsize)) // weitere Bits /=0 -> aufrunden
70 && ((mantlo & bit(shiftcount)) ==0)
73 { mantlo = (manthi << (32-shiftcount)) | (mantlo >> shiftcount);
74 manthi = manthi >> shiftcount;
78 { mantlo = (manthi << (32-shiftcount)) | (mantlo >> shiftcount);
79 manthi = manthi >> shiftcount;
83 if (manthi >= bit(DF_mant_len+1-32))
84 // Überlauf durchs Runden
85 { manthi = manthi>>1; exp = exp+1; } // Mantisse rechts schieben
87 if (exp > (sintL)(DF_exp_high-DF_exp_mid))
89 ((sint32)sign & bit(31))
90 | ((uint32)(bit(DF_exp_len)-1) << (DF_mant_len-32)); // Infinity
94 if (exp < (sintL)(DF_exp_low-DF_exp_mid))
95 { u.eksplicit.semhi = ((sint32)sign & bit(31)); // 0.0
100 ((sint32)sign & bit(31)) /* Vorzeichen */
101 | ((uint32)(exp+DF_exp_mid) << (DF_mant_len-32)) /* Exponent */
102 | ((uint32)manthi & (bit(DF_mant_len-32)-1)); /* Mantisse */
103 u.eksplicit.mlo = mantlo;
106 return u.machine_double;