]> www.ginac.de Git - cln.git/blob - src/float/dfloat/conv/cl_DF_from_double.cc
Remove exception hooks in favor of real C++ exceptions:
[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 namespace cln {
13
14 cl_heap_dfloat* cl_double_to_DF_pointer (const dfloatjanus& val_)
15 {
16       var dfloat val = val_.eksplicit;
17       #if (cl_word_size==64)
18       var uintL exp = (val >> DF_mant_len) & (bit(DF_exp_len)-1); // e
19       if (exp == 0) // e=0 ?
20         // vorzeichenbehaftete 0.0 oder subnormale Zahl
21         { if (!((val << 1) == 0) && underflow_allowed())
22             { throw floating_point_underflow_exception(); }
23             else
24             { return cl_DF_0; } // +/- 0.0 -> 0.0
25         }
26       elif (exp == 2047) // e=2047 ?
27         { if (!((val << (64-DF_mant_len)) == 0))
28             { throw floating_point_nan_exception(); } // NaN
29             else
30             { throw floating_point_overflow_exception(); } // Infinity, Overflow
31         }
32       else
33         { // Der Exponent muß um DF_exp_mid-1022 erhöht werden.
34           if ((DF_exp_mid>1022) && (exp > DF_exp_high-DF_exp_mid+1022))
35             { throw floating_point_overflow_exception(); } // Overflow
36           val += (sint64)(DF_exp_mid - 1022) << DF_mant_len;
37           return allocate_dfloat(val);
38         }
39       #else
40       var uintL exp = (val.semhi >> (DF_mant_len-32)) & (bit(DF_exp_len)-1); // e
41       if (exp == 0) // e=0 ?
42         // vorzeichenbehaftete 0.0 oder subnormale Zahl
43         { if (!(((val.semhi << 1) == 0) && (val.mlo == 0)) && underflow_allowed())
44             { throw floating_point_underflow_exception(); }
45             else
46             { return cl_DF_0; } // +/- 0.0 -> 0.0
47         }
48       elif (exp == 2047) // e=2047 ?
49         { if (!(((val.semhi << (64-DF_mant_len)) == 0) && (val.mlo == 0)))
50             { throw floating_point_nan_exception(); } // NaN
51             else
52             { throw floating_point_overflow_exception(); } // Infinity, Overflow
53         }
54       else
55         { // Der Exponent muß um DF_exp_mid-1022 erhöht werden.
56           if ((DF_exp_mid>1022) && (exp > DF_exp_high-DF_exp_mid+1022))
57             { throw floating_point_overflow_exception(); } // Overflow
58           val.semhi += (sint32)(DF_exp_mid - 1022) << (DF_mant_len-32);
59           return allocate_dfloat(val.semhi,val.mlo);
60         }
61       #endif
62 }
63
64 }  // namespace cln