]> www.ginac.de Git - cln.git/blob - src/float/ffloat/conv/cl_FF_from_float.cc
Finalize CLN 1.3.7 release.
[cln.git] / src / float / ffloat / conv / cl_FF_from_float.cc
1 // cl_float_to_FF_pointer().
2
3 // General includes.
4 #include "base/cl_sysdep.h"
5
6 // Specification.
7 #include "float/ffloat/cl_FF.h"
8
9 namespace cln {
10
11 // Implementation.
12
13 cl_private_thing cl_float_to_FF_pointer (const float x)
14 {
15       var union { ffloat eksplicit; float machine_float; } u;
16       u.machine_float = x;
17       var ffloat val = u.eksplicit;
18       var uintL exp = (val >> FF_mant_len) & (bit(FF_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 as_cl_private_thing(cl_FF_0); } // +/- 0.0 -> 0.0
25         }
26       elif (exp == 255) // e=255 ?
27         { if (!((val << (32-FF_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 FF_exp_mid-126 erhöht werden.
34           if ((FF_exp_mid>126) && (exp > FF_exp_high-FF_exp_mid+126))
35             { throw floating_point_overflow_exception(); } // Overflow
36           val += (FF_exp_mid - 126) << FF_mant_len;
37           #if defined(CL_WIDE_POINTERS)
38           return as_cl_private_thing(allocate_ffloat(val));
39           #else
40           return (cl_private_thing)allocate_ffloat(val);
41           #endif
42         }
43 }
44
45 }  // namespace cln