]> www.ginac.de Git - cln.git/blob - src/float/lfloat/elem/cl_LF_scale.cc
2006-04-25 Bruno Haible <bruno@clisp.org>
[cln.git] / src / float / lfloat / elem / cl_LF_scale.cc
1 // scale_float().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/lfloat.h"
8
9
10 // Implementation.
11
12 #include "cl_LF.h"
13 #include "cl_LF_impl.h"
14 #include "cl_F.h"
15
16 namespace cln {
17
18 const cl_LF scale_float (const cl_LF& x, sintC delta)
19 {
20   // Methode:
21   // delta=0 -> x als Ergebnis
22   // x=0.0 -> x als Ergebnis
23   // delta muß ein Integer betragsmäßig <= LF_exp_high-LF_exp_low sein.
24   // Neues LF mit um delta vergrößertem Exponenten bilden.
25       if (delta == 0) { return x; } // delta=0 -> x als Ergebnis
26       var uintL uexp = TheLfloat(x)->expo;
27       if (uexp==0) { return x; }
28       var uintC udelta = delta;
29       if (delta >= 0) {
30         // udelta = delta >=0
31         if (   ((uexp = uexp+udelta) < udelta) // Exponent-Überlauf?
32             || (uexp > LF_exp_high) // oder Exponent zu groß?
33            )
34           { cl_error_floating_point_overflow(); }
35       } else {
36         // delta <0, udelta = 2^intCsize+delta
37         if (   ((uintL)(-(uexp = uexp+udelta)) <= (uintC)(-udelta)) // oder Exponent-Unterlauf?
38             || (uexp < LF_exp_low) // oder Exponent zu klein?
39            )
40           { cl_error_floating_point_underflow(); }
41       }
42       var uintC len = TheLfloat(x)->len;
43       return encode_LFu(TheLfloat(x)->sign,uexp,arrayMSDptr(TheLfloat(x)->data,len),len);
44 }
45
46 }  // namespace cln