00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef PPL_Float_inlines_hh
00025 #define PPL_Float_inlines_hh 1
00026
00027 #include <climits>
00028
00029 namespace Parma_Polyhedra_Library {
00030
00031 inline int
00032 float_ieee754_half::is_inf() const {
00033 if (word == NEG_INF)
00034 return -1;
00035 if (word == POS_INF)
00036 return 1;
00037 return 0;
00038 }
00039
00040 inline int
00041 float_ieee754_half::is_nan() const {
00042 return (word & ~SGN_MASK) > POS_INF;
00043 }
00044
00045 inline int
00046 float_ieee754_half::is_zero() const {
00047 if (word == NEG_ZERO)
00048 return -1;
00049 if (word == POS_ZERO)
00050 return 1;
00051 return 0;
00052 }
00053
00054 inline void
00055 float_ieee754_half::negate() {
00056 word ^= SGN_MASK;
00057 }
00058
00059 inline int
00060 float_ieee754_half::sign_bit() const {
00061 return !!(word & SGN_MASK);
00062 }
00063
00064 inline void
00065 float_ieee754_half::dec() {
00066 --word;
00067 }
00068
00069 inline void
00070 float_ieee754_half::inc() {
00071 ++word;
00072 }
00073
00074 inline void
00075 float_ieee754_half::set_max(bool negative) {
00076 word = 0x7bff;
00077 if (negative)
00078 word |= SGN_MASK;
00079 }
00080
00081 inline void
00082 float_ieee754_half::build(bool negative, mpz_t mantissa, int exponent) {
00083 word = mpz_get_ui(mantissa) & ((1UL << MANTISSA_BITS) - 1);
00084 if (negative)
00085 word |= SGN_MASK;
00086 word |= static_cast<uint16_t>(exponent + EXPONENT_BIAS) << MANTISSA_BITS;
00087 }
00088
00089 inline int
00090 float_ieee754_single::is_inf() const {
00091 if (word == NEG_INF)
00092 return -1;
00093 if (word == POS_INF)
00094 return 1;
00095 return 0;
00096 }
00097
00098 inline int
00099 float_ieee754_single::is_nan() const {
00100 return (word & ~SGN_MASK) > POS_INF;
00101 }
00102
00103 inline int
00104 float_ieee754_single::is_zero() const {
00105 if (word == NEG_ZERO)
00106 return -1;
00107 if (word == POS_ZERO)
00108 return 1;
00109 return 0;
00110 }
00111
00112 inline void
00113 float_ieee754_single::negate() {
00114 word ^= SGN_MASK;
00115 }
00116
00117 inline int
00118 float_ieee754_single::sign_bit() const {
00119 return !!(word & SGN_MASK);
00120 }
00121
00122 inline void
00123 float_ieee754_single::dec() {
00124 --word;
00125 }
00126
00127 inline void
00128 float_ieee754_single::inc() {
00129 ++word;
00130 }
00131
00132 inline void
00133 float_ieee754_single::set_max(bool negative) {
00134 word = 0x7f7fffff;
00135 if (negative)
00136 word |= SGN_MASK;
00137 }
00138
00139 inline void
00140 float_ieee754_single::build(bool negative, mpz_t mantissa, int exponent) {
00141 word = mpz_get_ui(mantissa) & ((1UL << MANTISSA_BITS) - 1);
00142 if (negative)
00143 word |= SGN_MASK;
00144 word |= static_cast<uint32_t>(exponent + EXPONENT_BIAS) << MANTISSA_BITS;
00145 }
00146
00147 inline int
00148 float_ieee754_double::is_inf() const {
00149 if (lsp != LSP_INF)
00150 return 0;
00151 if (msp == MSP_NEG_INF)
00152 return -1;
00153 if (msp == MSP_POS_INF)
00154 return 1;
00155 return 0;
00156 }
00157
00158 inline int
00159 float_ieee754_double::is_nan() const {
00160 uint32_t a = msp & ~MSP_SGN_MASK;
00161 return a > MSP_POS_INF || (a == MSP_POS_INF && lsp != LSP_INF);
00162 }
00163
00164 inline int
00165 float_ieee754_double::is_zero() const {
00166 if (lsp != LSP_ZERO)
00167 return 0;
00168 if (msp == MSP_NEG_ZERO)
00169 return -1;
00170 if (msp == MSP_POS_ZERO)
00171 return 1;
00172 return 0;
00173 }
00174
00175 inline void
00176 float_ieee754_double::negate() {
00177 msp ^= MSP_SGN_MASK;
00178 }
00179
00180 inline int
00181 float_ieee754_double::sign_bit() const {
00182 return !!(msp & MSP_SGN_MASK);
00183 }
00184
00185 inline void
00186 float_ieee754_double::dec() {
00187 if (lsp == 0) {
00188 --msp;
00189 lsp = LSP_MAX;
00190 }
00191 else
00192 --lsp;
00193 }
00194
00195 inline void
00196 float_ieee754_double::inc() {
00197 if (lsp == LSP_MAX) {
00198 ++msp;
00199 lsp = 0;
00200 }
00201 else
00202 ++lsp;
00203 }
00204
00205 inline void
00206 float_ieee754_double::set_max(bool negative) {
00207 msp = 0x7fefffff;
00208 lsp = 0xffffffff;
00209 if (negative)
00210 msp |= MSP_SGN_MASK;
00211 }
00212
00213 inline void
00214 float_ieee754_double::build(bool negative, mpz_t mantissa, int exponent) {
00215 #if ULONG_MAX == 0xffffffffUL
00216 lsp = mpz_get_ui(mantissa);
00217 mpz_tdiv_q_2exp(mantissa, mantissa, 32);
00218 unsigned long m = mpz_get_ui(mantissa);
00219 #else
00220 unsigned long m = mpz_get_ui(mantissa);
00221 lsp = m;
00222 m >>= 32;
00223 #endif
00224 msp = m & ((1UL << (MANTISSA_BITS - 32)) - 1);
00225 if (negative)
00226 msp |= MSP_SGN_MASK;
00227 msp |= static_cast<uint32_t>(exponent + EXPONENT_BIAS)
00228 << (MANTISSA_BITS - 32);
00229 }
00230
00231 inline int
00232 float_ibm_single::is_inf() const {
00233 if (word == NEG_INF)
00234 return -1;
00235 if (word == POS_INF)
00236 return 1;
00237 return 0;
00238 }
00239
00240 inline int
00241 float_ibm_single::is_nan() const {
00242 return (word & ~SGN_MASK) > POS_INF;
00243 }
00244
00245 inline int
00246 float_ibm_single::is_zero() const {
00247 if (word == NEG_ZERO)
00248 return -1;
00249 if (word == POS_ZERO)
00250 return 1;
00251 return 0;
00252 }
00253
00254 inline void
00255 float_ibm_single::negate() {
00256 word ^= SGN_MASK;
00257 }
00258
00259 inline int
00260 float_ibm_single::sign_bit() const {
00261 return !!(word & SGN_MASK);
00262 }
00263
00264 inline void
00265 float_ibm_single::dec() {
00266 --word;
00267 }
00268
00269 inline void
00270 float_ibm_single::inc() {
00271 ++word;
00272 }
00273
00274 inline void
00275 float_ibm_single::set_max(bool negative) {
00276 word = 0x7f000000;
00277 if (negative)
00278 word |= SGN_MASK;
00279 }
00280
00281 inline void
00282 float_ibm_single::build(bool negative, mpz_t mantissa, int exponent) {
00283 word = mpz_get_ui(mantissa) & ((1UL << MANTISSA_BITS) - 1);
00284 if (negative)
00285 word |= SGN_MASK;
00286 word |= static_cast<uint32_t>(exponent + EXPONENT_BIAS) << MANTISSA_BITS;
00287 }
00288
00289 inline int
00290 float_intel_double_extended::is_inf() const {
00291 if (lsp != LSP_INF)
00292 return 0;
00293 uint32_t a = msp & MSP_NEG_INF;
00294 if (a == MSP_NEG_INF)
00295 return -1;
00296 if (a == MSP_POS_INF)
00297 return 1;
00298 return 0;
00299 }
00300
00301 inline int
00302 float_intel_double_extended::is_nan() const {
00303 return (msp & MSP_POS_INF) == MSP_POS_INF
00304 && lsp != LSP_INF;
00305 }
00306
00307 inline int
00308 float_intel_double_extended::is_zero() const {
00309 if (lsp != LSP_ZERO)
00310 return 0;
00311 uint32_t a = msp & MSP_NEG_INF;
00312 if (a == MSP_NEG_ZERO)
00313 return -1;
00314 if (a == MSP_POS_ZERO)
00315 return 1;
00316 return 0;
00317 }
00318
00319 inline void
00320 float_intel_double_extended::negate() {
00321 msp ^= MSP_SGN_MASK;
00322 }
00323
00324 inline int
00325 float_intel_double_extended::sign_bit() const {
00326 return !!(msp & MSP_SGN_MASK);
00327 }
00328
00329 inline void
00330 float_intel_double_extended::dec() {
00331 if ((lsp & LSP_DMAX) == 0) {
00332 --msp;
00333 lsp = (msp & MSP_NEG_INF) == 0 ? LSP_DMAX : LSP_NMAX;
00334 }
00335 else
00336 --lsp;
00337 }
00338
00339 inline void
00340 float_intel_double_extended::inc() {
00341 if ((lsp & LSP_DMAX) == LSP_DMAX) {
00342 ++msp;
00343 lsp = LSP_DMAX + 1;
00344 }
00345 else
00346 ++lsp;
00347 }
00348
00349 inline void
00350 float_intel_double_extended::set_max(bool negative) {
00351 msp = 0x00007ffe;
00352 lsp = 0xffffffffffffffffULL;
00353 if (negative)
00354 msp |= MSP_SGN_MASK;
00355 }
00356
00357 inline void
00358 float_intel_double_extended::build(bool negative,
00359 mpz_t mantissa, int exponent) {
00360 #if ULONG_MAX == 0xffffffffUL
00361 mpz_export(&lsp, 0, -1, 8, 0, 0, mantissa);
00362 #else
00363 lsp = mpz_get_ui(mantissa);
00364 #endif
00365 msp = (negative ? MSP_SGN_MASK : 0);
00366 msp |= static_cast<uint32_t>(exponent + EXPONENT_BIAS);
00367 }
00368
00369 inline int
00370 float_ieee754_quad::is_inf() const {
00371 if (lsp != LSP_INF)
00372 return 0;
00373 if (msp == MSP_NEG_INF)
00374 return -1;
00375 if (msp == MSP_POS_INF)
00376 return 1;
00377 return 0;
00378 }
00379
00380 inline int
00381 float_ieee754_quad::is_nan() const {
00382 return (msp & ~MSP_SGN_MASK) == MSP_POS_INF
00383 && lsp != LSP_INF;
00384 }
00385
00386 inline int
00387 float_ieee754_quad::is_zero() const {
00388 if (lsp != LSP_ZERO)
00389 return 0;
00390 if (msp == MSP_NEG_ZERO)
00391 return -1;
00392 if (msp == MSP_POS_ZERO)
00393 return 1;
00394 return 0;
00395 }
00396
00397 inline void
00398 float_ieee754_quad::negate() {
00399 msp ^= MSP_SGN_MASK;
00400 }
00401
00402 inline int
00403 float_ieee754_quad::sign_bit() const {
00404 return !!(msp & MSP_SGN_MASK);
00405 }
00406
00407 inline void
00408 float_ieee754_quad::dec() {
00409 if (lsp == 0) {
00410 --msp;
00411 lsp = LSP_MAX;
00412 }
00413 else
00414 --lsp;
00415 }
00416
00417 inline void
00418 float_ieee754_quad::inc() {
00419 if (lsp == LSP_MAX) {
00420 ++msp;
00421 lsp = 0;
00422 }
00423 else
00424 ++lsp;
00425 }
00426
00427 inline void
00428 float_ieee754_quad::set_max(bool negative) {
00429 msp = 0x7ffeffffffffffffULL;
00430 lsp = 0xffffffffffffffffULL;
00431 if (negative)
00432 msp |= MSP_SGN_MASK;
00433 }
00434
00435 inline void
00436 float_ieee754_quad::build(bool negative, mpz_t mantissa, int exponent) {
00437 uint64_t parts[2];
00438 mpz_export(parts, 0, -1, 8, 0, 0, mantissa);
00439 lsp = parts[0];
00440 msp = parts[1];
00441 msp &= ((1ULL << (MANTISSA_BITS - 64)) - 1);
00442 if (negative)
00443 msp |= MSP_SGN_MASK;
00444 msp |= static_cast<uint64_t>(exponent + EXPONENT_BIAS)
00445 << (MANTISSA_BITS - 64);
00446 }
00447
00448 #if PPL_SUPPORTED_FLOAT
00449 inline
00450 Float<float>::Float() {
00451 }
00452
00453 inline
00454 Float<float>::Float(float v) {
00455 u.number = v;
00456 }
00457
00458 inline float
00459 Float<float>::value() {
00460 return u.number;
00461 }
00462 #endif
00463
00464 #if PPL_SUPPORTED_DOUBLE
00465 inline
00466 Float<double>::Float() {
00467 }
00468
00469 inline
00470 Float<double>::Float(double v) {
00471 u.number = v;
00472 }
00473
00474 inline double
00475 Float<double>::value() {
00476 return u.number;
00477 }
00478 #endif
00479
00480 #if PPL_SUPPORTED_LONG_DOUBLE
00481 inline
00482 Float<long double>::Float() {
00483 }
00484
00485 inline
00486 Float<long double>::Float(long double v) {
00487 u.number = v;
00488 }
00489
00490 inline long double
00491 Float<long double>::value() {
00492 return u.number;
00493 }
00494 #endif
00495
00496
00497 }
00498
00499 #endif // !defined(PPL_Float_inlines_hh)