]> www.ginac.de Git - cln.git/blob - src/float/sfloat/elem/cl_SF_ftrunc.cc
* */*: Convert encoding from ISO 8859-1 to UTF-8.
[cln.git] / src / float / sfloat / elem / cl_SF_ftrunc.cc
1 // ftruncate().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/sfloat.h"
8
9
10 // Implementation.
11
12 #include "cl_SF.h"
13
14 namespace cln {
15
16 const cl_SF ftruncate (const cl_SF& x)
17 {
18 // Methode:
19 // x = 0.0 oder e<=0 -> Ergebnis 0.0
20 // 1<=e<=16 -> letzte (17-e) Bits der Mantisse auf 0 setzen,
21 //             Exponent und Vorzeichen beibehalten
22 // e>=17 -> Ergebnis x
23       var uintL uexp = SF_uexp(x); // e + SF_exp_mid
24       if (uexp <= SF_exp_mid) // 0.0 oder e<=0 ?
25         { return SF_0; }
26         else
27         { if (uexp > SF_exp_mid+SF_mant_len) // e > 16 ?
28             { return x; }
29             else
30             { return cl_SF_from_word(
31                 x.word & // Bitmaske: Bits 16-e..0 gelöscht, alle anderen gesetzt
32                 ~(bit(SF_mant_len+SF_mant_shift + 1+SF_exp_mid-uexp) - bit(SF_mant_shift))
33                 );
34             }
35         }
36 }
37
38 }  // namespace cln