]> www.ginac.de Git - cln.git/blob - src/float/ffloat/conv/cl_FF_from_float.cc
* Also filter out SCCS subdirs while recursing and searching for
[cln.git] / src / float / ffloat / conv / cl_FF_from_float.cc
1 // cl_float_to_FF().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_FF.h"
8
9 namespace cln {
10
11 // Implementation.
12
13 cl_private_thing cl_float_to_FF_pointer (const ffloatjanus& val_)
14 {
15       var ffloat val = val_.eksplicit;
16       var uintL exp = (val >> FF_mant_len) & (bit(FF_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 as_cl_private_thing(cl_FF_0); } // +/- 0.0 -> 0.0
23         }
24       elif (exp == 255) // e=255 ?
25         { if (!((val << (32-FF_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 FF_exp_mid-126 erhöht werden.
32           if ((FF_exp_mid>126) && (exp > FF_exp_high-FF_exp_mid+126))
33             { cl_error_floating_point_overflow(); } // Overflow
34           val += (FF_exp_mid - 126) << FF_mant_len;
35           #if defined(CL_WIDE_POINTERS)
36           return as_cl_private_thing(allocate_ffloat(val));
37           #else
38           return (cl_private_thing)allocate_ffloat(val);
39           #endif
40         }
41 }
42
43 }  // namespace cln