]> www.ginac.de Git - cln.git/blob - src/float/dfloat/conv/cl_DF_from_double.cc
Initial revision
[cln.git] / src / float / dfloat / conv / cl_DF_from_double.cc
1 // cl_double_to_FF().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_DF.h"
8
9
10 // Implementation.
11
12 cl_heap_dfloat* cl_double_to_DF_pointer (const dfloatjanus& val_)
13 {
14       var dfloat val = val_.eksplicit;
15       #if (cl_word_size==64)
16       var uintL exp = (val >> DF_mant_len) & (bit(DF_exp_len)-1); // e
17       if (exp == 0) // e=0 ?
18         // vorzeichenbehaftete 0.0 oder subnormale Zahl
19         { if (!((val << 1) == 0) && underflow_allowed())
20             { cl_error_floating_point_underflow(); }
21             else
22             { return cl_DF_0; } // +/- 0.0 -> 0.0
23         }
24       elif (exp == 2047) // e=2047 ?
25         { if (!((val << (64-DF_mant_len)) == 0))
26             { cl_error_floating_point_nan(); } // NaN
27             else
28             { cl_error_floating_point_overflow(); } // Infinity, Overflow
29         }
30       else
31         { // Der Exponent muß um DF_exp_mid-1022 erhöht werden.
32           if ((DF_exp_mid>1022) && (exp > DF_exp_high-DF_exp_mid+1022))
33             { cl_error_floating_point_overflow(); } // Overflow
34           val += (sint64)(DF_exp_mid - 1022) << DF_mant_len;
35           return allocate_dfloat(val);
36         }
37       #else
38       var uintL exp = (val.semhi >> (DF_mant_len-32)) & (bit(DF_exp_len)-1); // e
39       if (exp == 0) // e=0 ?
40         // vorzeichenbehaftete 0.0 oder subnormale Zahl
41         { if (!(((val.semhi << 1) == 0) && (val.mlo == 0)) && underflow_allowed())
42             { cl_error_floating_point_underflow(); }
43             else
44             { return cl_DF_0; } // +/- 0.0 -> 0.0
45         }
46       elif (exp == 2047) // e=2047 ?
47         { if (!(((val.semhi << (64-DF_mant_len)) == 0) && (val.mlo == 0)))
48             { cl_error_floating_point_nan(); } // NaN
49             else
50             { cl_error_floating_point_overflow(); } // Infinity, Overflow
51         }
52       else
53         { // Der Exponent muß um DF_exp_mid-1022 erhöht werden.
54           if ((DF_exp_mid>1022) && (exp > DF_exp_high-DF_exp_mid+1022))
55             { cl_error_floating_point_overflow(); } // Overflow
56           val.semhi += (sint32)(DF_exp_mid - 1022) << (DF_mant_len-32);
57           return allocate_dfloat(val.semhi,val.mlo);
58         }
59       #endif
60 }