1 // cl_float_to_FF_pointer().
4 #include "base/cl_sysdep.h"
7 #include "float/ffloat/cl_FF.h"
13 cl_private_thing cl_float_to_FF_pointer (const float x)
15 var union { ffloat eksplicit; float machine_float; } u;
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(); }
24 { return as_cl_private_thing(cl_FF_0); } // +/- 0.0 -> 0.0
26 elif (exp == 255) // e=255 ?
27 { if (!((val << (32-FF_mant_len)) == 0))
28 { throw floating_point_nan_exception(); } // NaN
30 { throw floating_point_overflow_exception(); } // Infinity, Overflow
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));
40 return (cl_private_thing)allocate_ffloat(val);