7 #include "cln/dfloat.h"
17 float float_approx (const cl_DF& x)
19 union { ffloat eksplicit; float machine_float; } u;
23 #if (cl_word_size==64)
25 DF_decode(x, { return 0.0; }, sign=,exp=,mant=);
26 // 52-23=29 Bits wegrunden:
27 var const int shiftcount = DF_mant_len-FF_mant_len;
28 if ( ((mant & bit(shiftcount-1)) ==0) // Bit 28 war 0 -> abrunden
29 || ( ((mant & (bit(shiftcount-1)-1)) ==0) // war 1, Bits 27..0 >0 -> aufrunden
31 && ((mant & bit(shiftcount)) ==0)
34 { mant = mant >> shiftcount; }
37 { mant = mant >> shiftcount;
39 if (mant >= bit(FF_mant_len+1))
40 // Überlauf durchs Runden
41 { mant = mant>>1; exp = exp+1; } // Mantisse rechts schieben
46 DF_decode2(x, { return 0.0; }, sign=,exp=,manthi=,mantlo=);
47 // 52-23=29 Bits wegrunden:
48 var const int shiftcount = DF_mant_len-FF_mant_len;
49 manthi = (manthi << (32-shiftcount)) | (mantlo >> shiftcount);
50 if ( ((mantlo & bit(shiftcount-1)) ==0) // Bit 28 war 0 -> abrunden
51 || ( ((mantlo & (bit(shiftcount-1)-1)) ==0) // war 1, Bits 27..0 >0 -> aufrunden
53 && ((mantlo & bit(shiftcount)) ==0)
60 if (manthi >= bit(FF_mant_len+1))
61 // Überlauf durchs Runden
62 { manthi = manthi>>1; exp = exp+1; } // Mantisse rechts schieben
66 if (exp > (sintL)(FF_exp_high-FF_exp_mid))
67 { u.eksplicit = make_FF_word(sign,bit(FF_exp_len)-1,0); } // Infinity
69 if (exp < (sintL)(FF_exp_low-FF_exp_mid))
70 { u.eksplicit = make_FF_word(sign,0,0); } // 0.0
72 { u.eksplicit = make_FF_word(sign,exp+FF_exp_mid,mant); }
73 return u.machine_float;