1 // cl_LF_shortenwith(). 2 3 // General includes. 4 #include "base/cl_sysdep.h" 5 6 // Specification. 7 #include "float/lfloat/cl_LF.h" 8 9 10 // Implementation. 11 12 #include "base/cl_inline2.h" 13 #include "float/lfloat/misc/cl_LF_precision.cc" 14 #include "base/cl_inline.h" 15 #include "float/lfloat/misc/cl_LF_exponent.cc" 16 17 namespace cln { 18 cl_LF_shortenwith(const cl_LF & x,const cl_LF & y)19const cl_LF cl_LF_shortenwith (const cl_LF& x, const cl_LF& y) 20 { 21 // Methode: 22 // x = 0.0 -> Precision egal, return x. 23 // ex := float_exponent(x), dx := float_digits(x), 1 ulp(x) = 2^(ex-dx). 24 // ey := float_exponent(y). 25 // Falls ex-dx < ey, x von Precision dx auf ex-ey verkürzen. 26 var sintE ey = float_exponent_inline(y); 27 var sintE ex = float_exponent_inline(x); 28 var uintC dx = float_precision_inline(x); 29 if (dx==0) // zerop(x) ? 30 return x; 31 var sintE ulpx = ex - dx; 32 if ((ex<0 && ulpx>=0) // underflow? 33 || (ulpx < ey) 34 ) { // Now ex-dx < ey, hence ex-ey < dx. 35 var uintL new_dx; 36 if (ex < ey) 37 new_dx = intDsize*LF_minlen; 38 else if ((new_dx = ex - ey) < intDsize*LF_minlen) 39 new_dx = intDsize*LF_minlen; 40 var uintL len = ceiling(new_dx,intDsize); 41 if (intDsize*len < dx) 42 return shorten(x,len); 43 else 44 return x; 45 } else 46 return x; 47 } 48 49 } // namespace cln 50