1 // cl_FF_to_SF().
2 
3 // General includes.
4 #include "base/cl_sysdep.h"
5 
6 // Specification.
7 #include "float/cl_F.h"
8 
9 
10 // Implementation.
11 
12 #include "float/ffloat/cl_FF.h"
13 #include "float/sfloat/cl_SF.h"
14 
15 namespace cln {
16 
cl_FF_to_SF(const cl_FF & x)17 const cl_SF cl_FF_to_SF (const cl_FF& x)
18 {
19 	// x entpacken:
20 	var cl_signean sign;
21 	var sintL exp;
22 	var uint32 mant;
23 	FF_decode(x, { return SF_0; }, sign=,exp=,mant=);
24 	// 23-16 Bits wegrunden:
25 	var const int shiftcount = FF_mant_len-SF_mant_len;
26 	if ( ((mant & bit(shiftcount-1)) ==0) // Bit 6 war 0 -> abrunden
27 	     || ( ((mant & (bit(shiftcount-1)-1)) ==0) // war 1, Bits 5..0 >0 -> aufrunden
28 	          // round-to-even
29 	          && ((mant & bit(shiftcount)) ==0)
30 	   )    )
31 	  // abrunden
32 	  { mant = mant >> shiftcount; }
33 	  else
34 	  // aufrunden
35 	  { mant = mant >> shiftcount;
36 	    mant = mant+1;
37 	    if (mant >= bit(SF_mant_len+1))
38 	      // Überlauf durchs Runden
39 	      { mant = mant>>1; exp = exp+1; } // Mantisse rechts schieben
40 	  }
41 	return encode_SF(sign,exp,mant);
42 }
43 
44 }  // namespace cln
45