7 #include "cln/lfloat.h"
13 #include "cl_LF_impl.h"
19 float float_approx (const cl_LF& x)
26 LF_decode(x, { return 0.0; }, sign=,exp=,ptr=,len=,);
27 // intDsize*len-FF_mant_len-1 Bits der Mantisse wegrunden:
28 // erste k := ceiling(FF_mant_len+2,intDsize) Digits nach mant holen:
30 var uint64 mant = get_max64_Dptr(FF_mant_len+2,ptr);
32 var uint32 mant = get_max32_Dptr(FF_mant_len+2,ptr);
34 ptr = ptr mspop ceiling(FF_mant_len+2,intDsize);
35 var const int shiftcount = ceiling(FF_mant_len+2,intDsize)*intDsize-(FF_mant_len+1);
36 if ( ((mant & bit(shiftcount-1)) ==0) // Bit 7 war 0 -> abrunden
37 || ( ((mant & (bit(shiftcount-1)-1)) ==0) // war 1, Bits 6..0 >0 -> aufrunden
38 && !test_loop_msp(ptr,len-ceiling(FF_mant_len+2,intDsize)) // weitere Bits /=0 -> aufrunden
40 && ((mant & bit(shiftcount)) ==0)
43 { mant = mant >> shiftcount; }
46 { mant = mant >> shiftcount;
48 if (mant >= bit(FF_mant_len+1))
49 // Überlauf durchs Runden
50 { mant = mant>>1; exp = exp+1; } // Mantisse rechts schieben
52 union { ffloat eksplicit; float machine_float; } u;
53 if (exp > (sintL)(FF_exp_high-FF_exp_mid))
54 { u.eksplicit = make_FF_word(sign,bit(FF_exp_len)-1,0); } // Infinity
56 if (exp < (sintL)(FF_exp_low-FF_exp_mid))
57 { u.eksplicit = make_FF_word(sign,0,0); } // 0.0
59 { u.eksplicit = make_FF_word(sign,exp+FF_exp_mid,mant); }
60 return u.machine_float;