4 #include "base/cl_sysdep.h"
7 #include "float/lfloat/cl_LF.h"
12 #include "float/lfloat/cl_LF_impl.h"
13 #include "base/digitseq/cl_DS.h"
14 #include "float/cl_F.h"
18 const cl_LF shorten (const cl_LF& x, uintC len)
20 // x = 0.0 braucht nicht abgefangen zu werden, da bei Mantisse 0 dann
21 // sowieso abgerundet wird, die Mantisse also 0 bleibt.
22 var Lfloat y = allocate_lfloat(len,TheLfloat(x)->expo,TheLfloat(x)->sign); // neues LF
23 { var uintC oldlen = TheLfloat(x)->len; // alte Länge, > len
24 // Mantisse von x nach y kopieren:
25 copy_loop_msp(arrayMSDptr(TheLfloat(x)->data,oldlen),arrayMSDptr(TheLfloat(y)->data,len),len);
26 // Entscheiden, ob auf- oder abrunden:
27 var uintD* ptr = arrayMSDptr(TheLfloat(x)->data,oldlen) mspop len;
28 if ( ((sintD)mspref(ptr,0) >= 0) // nächstes Bit eine 0 -> abrunden
29 || ( ((mspref(ptr,0) & ((uintD)bit(intDsize-1)-1)) ==0) // eine 1 und alles weitere Nullen?
30 && !test_loop_msp(ptr mspop 1,oldlen-len-1)
32 && ((lspref(ptr,0) & bit(0)) ==0)
38 { if ( inc_loop_lsp(arrayLSDptr(TheLfloat(y)->data,len),len) )
39 // Übertrag durch Aufrunden
40 { mspref(arrayMSDptr(TheLfloat(y)->data,len),0) = bit(intDsize-1); // Mantisse := 10...0
42 if (++(TheLfloat(y)->expo) == LF_exp_high+1) { throw floating_point_overflow_exception(); }