/usr/include/bound_def.h is in libapron-dev 0.9.10-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | /* ********************************************************************** */
/* bound_def.h: numbers used for bounds */
/* ********************************************************************** */
#ifndef _BOUND_DEF_H_
#define _BOUND_DEF_H_
#ifndef _BOUND_H_
#error "File bound_def.h should not be included directly, only via bound.h"
#endif
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(NUM_MAX) || defined(NUM_NUMRAT) || defined(NUM_NUMFLT)
typedef num_t bound_t;
#define bound_numref(a) a
#define _bound_inf(a)
#define BOUND_NUM
#else
typedef struct _bound_t {
num_t num; /* always allocated, even if inf=1 */
char inf; /* 1 => +/-oo; the sign of num decides the sign of the oo
0 => >-oo, <+oo */
} bound_t[1];
#define bound_numref(a) a->num
#define _bound_inf(a) a->inf = 0
#define BOUND_NUM_INF
#endif
/* ---------------------------------------------------------------------- */
static inline bool bound_infty(bound_t a)
#if defined(NUM_NUMFLT)
{ return numflt_infty(a); }
#elif defined(NUM_MAX)
{ return (*a>=NUM_MAX || *a<=-NUM_MAX); }
#elif defined(NUM_NUMRAT)
{ return numint_sgn(numrat_denref(a))==0; }
#else
{ return (bool)a->inf; }
#endif
/* ---------------------------------------------------------------------- */
static inline void bound_set_infty(bound_t a, int sgn)
#if defined(NUM_NUMFLT)
{ assert(sgn); numflt_set_infty(a,sgn); }
#elif defined(NUM_MAX)
{ assert(sgn); *a = sgn>0 ? NUM_MAX : -NUM_MAX; }
#elif defined(NUM_NUMRAT)
{
assert(sgn);
numint_set_int(numrat_numref(a),sgn>0 ? 1 : -1);
numint_set_int(numrat_denref(a),0);
}
#else
{
assert(sgn);
num_set_int(a->num,sgn>0 ? 1 : -1);
a->inf = 1;
}
#endif
/* ---------------------------------------------------------------------- */
static inline void bound_init_set_infty(bound_t a, int sgn)
{
num_init(bound_numref(a));
bound_set_infty(a,sgn);
}
static inline void bound_swap(bound_t a, bound_t b)
{
#if defined(BOUND_NUM_INF)
int t = a->inf; a->inf = b->inf; b->inf = t;
#endif
num_swap(bound_numref(a),bound_numref(b));
}
static inline int bound_sgn(bound_t a)
{ return num_sgn(bound_numref(a)); }
/* ====================================================================== */
/* Assignement */
/* ====================================================================== */
#if defined(BOUND_NUM)
static inline void bound_set(bound_t a, bound_t b)
{ num_set(a,b); }
static inline void bound_set_array(bound_t* a, bound_t* b, size_t size)
{ num_set_array(a,b,size); }
#elif defined(NUM_NATIVE)
static inline void bound_set(bound_t a, bound_t b)
{ *a = *b; }
static inline void bound_set_array(bound_t* a, bound_t* b, size_t size)
{ memcpy(a,b,size*sizeof(bound_t)); }
#else
static inline void bound_set(bound_t a, bound_t b)
{ num_set(a->num,b->num); a->inf = b->inf; }
static inline void bound_set_array(bound_t* a, bound_t* b, size_t size)
{
size_t i;
for (i=0; i<size; i++) bound_set(a[i],b[i]);
}
#endif
static inline void bound_set_int(bound_t a, long int i)
{ num_set_int(bound_numref(a),i); _bound_inf(a); }
static inline void bound_set_num(bound_t a, num_t b)
{ num_set(bound_numref(a),b); _bound_inf(a); }
/* ====================================================================== */
/* Constructors and Destructors */
/* ====================================================================== */
static inline void bound_init(bound_t a)
{ num_init(bound_numref(a)); _bound_inf(a); }
static inline void bound_init_set_int(bound_t a, long int i)
{ num_init_set_int(bound_numref(a),i); _bound_inf(a); }
static inline void bound_clear(bound_t a)
{ num_clear(bound_numref(a)); }
#if defined(BOUND_NUM)
static inline void bound_init_array(bound_t* a, size_t size)
{ num_init_array(a,size); }
static inline void bound_init_set(bound_t a, bound_t b)
{ num_init_set(a,b); }
static inline void bound_clear_array(bound_t* a, size_t size)
{ num_clear_array(a,size); }
#else
static inline void bound_init_array(bound_t* a, size_t size)
{
size_t i;
for (i=0;i<size;i++) bound_init(a[i]);
}
static inline void bound_init_set(bound_t a, bound_t b)
{
if (bound_infty(b)){
bound_init_set_infty(a,bound_sgn(b));
} else {
num_init_set(bound_numref(a),bound_numref(b));
_bound_inf(a);
}
}
static inline void bound_clear_array(bound_t* a, size_t size)
{
#if !defined(NUM_NATIVE)
size_t i;
for (i=0;i<size;i++) bound_clear(a[i]);
#endif
}
#endif
/* ====================================================================== */
/* Arithmetic Operations */
/* ====================================================================== */
/* +oo + -oo \
-oo + +oo | undefined
+oo - +oo |
-oo - -oo /
+oo + x = +oo - x = x - -oo = +oo
-oo + x = -oo - x = x - +oo = -oo
0 * +oo = +oo * 0 = 0 * -oo = -oo * 0 = 0
x * +oo = +oo * x = sign(x) * oo if x!=0
x * -oo = -oo * x = -sign(x) * oo if x!=0
0 / x = x / +oo = x / -oo = 0
x / 0 = sign(x) * oo if x!=0
+oo / x = sign(x) * oo if x!=0,+oo,-oo
-oo / x = -sign(x) * oo if x!=0,+oo,-oo
*/
#if defined (NUM_MAX) && defined(NUM_NUMFLT)
static inline void bound_neg(bound_t a, bound_t b)
{ num_neg(a,b); }
static inline void bound_abs(bound_t a, bound_t b)
{ num_abs(a,b); }
static inline void bound_add(bound_t a, bound_t b, bound_t c)
{ num_add(a,b,c); }
static inline void bound_add_uint(bound_t a, bound_t b, unsigned long int c)
{ num_add_uint(a,b,c); }
static inline void bound_add_num(bound_t a, bound_t b, num_t c)
{ num_add(a,b,c); }
static inline void bound_sub(bound_t a, bound_t b, bound_t c)
{ num_sub(a,b,c); }
static inline void bound_sub_uint(bound_t a, bound_t b, unsigned long int c)
{ num_sub_uint(a,b,c); }
static inline void bound_sub_num(bound_t a, bound_t b, num_t c)
{ num_sub(a,b,c); }
static inline void bound_mul(bound_t a, bound_t b, bound_t c)
{ if (!bound_sgn(b) || !bound_sgn(c)) num_set_int(a,0); else num_mul(a,b,c); }
static inline void bound_mul_num(bound_t a, bound_t b, num_t c)
{ if (!bound_sgn(b) || !num_sgn(c)) num_set_int(a,0); else num_mul(a,b,c); }
static inline void bound_mul_2(bound_t a, bound_t b)
{ num_mul_2(a,b); }
static inline void bound_div(bound_t a, bound_t b, bound_t c)
{
if (!bound_sgn(b) || bound_infty(c)) bound_set_int(a,0);
else if (!bound_sgn(c)) bound_set_infty(a,bound_sgn(b));
else num_div(a,b,c);
}
static inline void bound_div_num(bound_t a, bound_t b, num_t c)
{
if (!bound_sgn(b)) bound_set_int(a,0);
else if (!num_sgn(c)) bound_set_infty(a,bound_sgn(b));
else num_div(a,b,c);
}
static inline void bound_div_2(bound_t a, bound_t b)
{ num_div_2(a,b); }
#else
static inline void bound_neg(bound_t a, bound_t b)
{
if (bound_infty(b)) bound_set_infty(a,-bound_sgn(b));
else { num_neg(bound_numref(a),bound_numref(b)); _bound_inf(a); }
}
static inline void bound_abs(bound_t a, bound_t b)
{ num_abs(bound_numref(a),bound_numref(b)); }
static inline void bound_add(bound_t a, bound_t b, bound_t c)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else if (bound_infty(c)) bound_set_infty(a,bound_sgn(c));
else { num_add(bound_numref(a),bound_numref(b),bound_numref(c)); _bound_inf(a); }
}
static inline void bound_add_uint(bound_t a, bound_t b, unsigned long int c)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else { num_add_uint(bound_numref(a),bound_numref(b),c); _bound_inf(a); }
}
static inline void bound_add_num(bound_t a, bound_t b, num_t c)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else { num_add(bound_numref(a),bound_numref(b),c); _bound_inf(a); }
}
static inline void bound_sub(bound_t a, bound_t b, bound_t c)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else if (bound_infty(c)) bound_set_infty(a,-bound_sgn(c));
else { num_sub(bound_numref(a),bound_numref(b),bound_numref(c)); _bound_inf(a); }
}
static inline void bound_sub_uint(bound_t a, bound_t b, unsigned long int c)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else { num_sub_uint(bound_numref(a),bound_numref(b),c); _bound_inf(a); }
}
static inline void bound_sub_num(bound_t a, bound_t b, num_t c)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else { num_sub(bound_numref(a),bound_numref(b),c); _bound_inf(a); }
}
static inline void bound_mul(bound_t a, bound_t b, bound_t c)
{
if (!bound_sgn(b) || !bound_sgn(c)) bound_set_int(a,0);
else if (bound_infty(b) || bound_infty(c)) bound_set_infty(a,bound_sgn(b)*bound_sgn(c));
else { num_mul(bound_numref(a),bound_numref(b),bound_numref(c)); _bound_inf(a); }
}
static inline void bound_mul_num(bound_t a, bound_t b, num_t c)
{
if (!bound_sgn(b) || !num_sgn(c)) bound_set_int(a,0);
else if (bound_infty(b)) bound_set_infty(a,bound_sgn(b)*num_sgn(c));
else { num_mul(bound_numref(a),bound_numref(b),c); _bound_inf(a); }
}
static inline void bound_mul_2(bound_t a, bound_t b)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else { num_mul_2(bound_numref(a),bound_numref(b)); _bound_inf(a); }
}
static inline void bound_div(bound_t a, bound_t b, bound_t c)
{
if (!bound_sgn(b) || bound_infty(c)) bound_set_int(a,0);
else if (!bound_sgn(c)) bound_set_infty(a,bound_sgn(b));
else if (bound_infty(b)) bound_set_infty(a,bound_sgn(b)*bound_sgn(c));
else { num_div(bound_numref(a),bound_numref(b),bound_numref(c)); _bound_inf(a); }
}
static inline void bound_div_num(bound_t a, bound_t b, num_t c)
{
if (!bound_sgn(b)) bound_set_int(a,0);
else if (!num_sgn(c)) bound_set_infty(a,bound_sgn(b));
else if (bound_infty(b)) bound_set_infty(a,bound_sgn(b)*num_sgn(c));
else { num_div(bound_numref(a),bound_numref(b),c); _bound_inf(a); }
}
static inline void bound_div_2(bound_t a, bound_t b)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else { num_div_2(bound_numref(a),bound_numref(b)); _bound_inf(a); }
}
#endif
#if defined(NUM_MAX) || defined(NUM_NUMFLT)
static inline void bound_min(bound_t a, bound_t b, bound_t c)
{ num_min(a,b,c); }
static inline void bound_max(bound_t a, bound_t b, bound_t c)
{ num_max(a,b,c); }
#else
static inline void bound_min(bound_t a, bound_t b, bound_t c)
{
if (bound_infty(b)) if (bound_sgn(b)>0) bound_set(a,c); else bound_set(a,b);
else if (bound_infty(c)) if (bound_sgn(c)>0) bound_set(a,b); else bound_set(a,c);
else { num_min(bound_numref(a),bound_numref(b),bound_numref(c)); _bound_inf(a); }
}
static inline void bound_max(bound_t a, bound_t b, bound_t c)
{
if (bound_infty(b)) if (bound_sgn(b)>0) bound_set(a,b); else bound_set(a,c);
else if (bound_infty(c)) if (bound_sgn(c)>0) bound_set(a,c); else bound_set(a,b);
else { num_max(bound_numref(a),bound_numref(b),bound_numref(c)); _bound_inf(a); }
}
#endif
static inline void bound_floor(bound_t a, bound_t b)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else { num_floor(bound_numref(a),bound_numref(b)); _bound_inf(a); }
}
static inline void bound_ceil(bound_t a, bound_t b)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else { num_ceil(bound_numref(a),bound_numref(b)); _bound_inf(a); }
}
static inline void bound_trunc(bound_t a, bound_t b)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else { num_trunc(bound_numref(a),bound_numref(b)); _bound_inf(a); }
}
static inline void bound_sqrt(bound_t up, bound_t down, bound_t b)
{
if (bound_infty(b)) {
bound_set_infty(up,1);
bound_set_infty(down,1);
}
else {
num_sqrt(bound_numref(up),bound_numref(down),bound_numref(b));
_bound_inf(up);
_bound_inf(down);
}
}
static inline void bound_to_float(bound_t a, bound_t b)
{
if (bound_infty(b) || !num_fits_float(bound_numref(b)))
bound_set_infty(a,bound_sgn(b));
else {
double d;
double_set_num(&d,bound_numref(b));
num_set_double(bound_numref(a),(double)((float)d));
_bound_inf(a);
}
}
static inline void bound_to_double(bound_t a, bound_t b)
{
if (bound_infty(b) || !num_fits_double(bound_numref(b)))
bound_set_infty(a,bound_sgn(b));
else {
double d;
double_set_num(&d,bound_numref(b));
num_set_double(bound_numref(a),d);
_bound_inf(a);
}
}
static inline void bound_mul_2exp(bound_t a, bound_t b, int c)
{
if (bound_infty(b)) bound_set_infty(a,bound_sgn(b));
else { num_mul_2exp(bound_numref(a),bound_numref(b),c); }
}
/* ====================================================================== */
/* Arithmetic Tests */
/* ====================================================================== */
#if defined(NUM_MAX) || defined(NUM_NUMFLT)
static inline int bound_cmp(bound_t a, bound_t b)
{ return num_cmp(a,b); }
static inline int bound_cmp_int(bound_t a, long int b)
{ return num_cmp_int(a,b); }
static inline int bound_cmp_num(bound_t a, num_t b)
{ return num_cmp(a,b); }
static inline bool bound_equal(bound_t a, bound_t b)
{ return num_equal(a,b); }
static inline int bound_hash(bound_t a)
{ long int hash; int_set_num(&hash,bound_numref(a)); return hash; }
#else
static inline int bound_cmp(bound_t a, bound_t b)
{
if (bound_infty(a)){
if (bound_infty(b)) return (bound_sgn(a)-bound_sgn(b))/2;
else return bound_sgn(a);
} else {
if (bound_infty(b)) return -bound_sgn(b);
else return num_cmp(bound_numref(a),bound_numref(b));
}
}
static inline int bound_cmp_int(bound_t a, long int b)
{
if (bound_infty(a)) return bound_sgn(a);
else return num_cmp_int(bound_numref(a),b);
}
static inline int bound_cmp_num(bound_t a, num_t b)
{
if (bound_infty(a)) return bound_sgn(a);
else return num_cmp(bound_numref(a),b);
}
static inline bool bound_equal(bound_t a, bound_t b)
{
if (bound_infty(a)){
return bound_infty(b) && bound_sgn(a)==bound_sgn(b);
} else {
if (bound_infty(b)) return false;
else return num_equal(bound_numref(a),bound_numref(b));
}
}
static inline int bound_hash(bound_t a)
{ if (bound_infty(a))
return bound_sgn(a)>0 ? INT_MAX : INT_MIN;
else {
long int hash;
int_set_num(&hash,bound_numref(a));
return hash;
}
}
#endif
/* ====================================================================== */
/* Printing */
/* ====================================================================== */
static inline void bound_fprint(FILE* stream, bound_t a)
{
if (bound_infty(a)) fprintf(stream,"%coo",bound_sgn(a)>0 ? '+' : '-');
else num_fprint(stream,bound_numref(a));
}
static inline void bound_print(bound_t a)
{
bound_fprint(stdout,a);
}
static inline int bound_snprint(char* s, size_t size, bound_t a)
{
if (bound_infty(a)) return snprintf(s,size,"%coo",bound_sgn(a)>0 ? '+' : '-');
else return num_snprint(s,size,bound_numref(a));
}
/* ====================================================================== */
/* Conversions */
/* ====================================================================== */
/* Convert an ap_scalar_t into a bound_t */
static inline
bool bound_set_ap_scalar(bound_t a, ap_scalar_t* b)
{
switch (b->discr){
case AP_SCALAR_MPQ:
if (mpz_sgn(mpq_denref(b->val.mpq))==0){
bound_set_infty(a,mpz_sgn(mpq_numref(b->val.mpq)));
return true;
}
else {
_bound_inf(a);
return num_set_mpq(bound_numref(a),b->val.mpq);
}
break;
case AP_SCALAR_DOUBLE:
if (isinf(b->val.dbl)) {
if (b->val.dbl>0) bound_set_infty(a,1);
else bound_set_infty(a,-1);
return true;
}
else {
_bound_inf(a);
return num_set_double(bound_numref(a),b->val.dbl);
}
break;
case AP_SCALAR_MPFR:
if (mpfr_inf_p(b->val.mpfr)) {
if (mpfr_sgn(b->val.mpfr)>0) bound_set_infty(a,1);
else bound_set_infty(a,-1);
return true;
}
else {
_bound_inf(a);
return num_set_mpfr(bound_numref(a),b->val.mpfr);
}
break;
default:
abort();
return false;
}
}
/* Convert a bound_t into an ap_scalar_t */
static inline bool ap_scalar_set_bound(ap_scalar_t* a, bound_t b)
{
ap_scalar_reinit(a,NUM_AP_SCALAR);
if (bound_infty(b)) { ap_scalar_set_infty(a,bound_sgn(b)); return true; }
else {
switch (NUM_AP_SCALAR) {
case AP_SCALAR_DOUBLE: return double_set_num(&a->val.dbl,bound_numref(b));
case AP_SCALAR_MPQ: return mpq_set_num(a->val.mpq,bound_numref(b));
case AP_SCALAR_MPFR: return mpfr_set_num(a->val.mpfr,bound_numref(b));
default: abort(); return false;
}
}
}
/* ====================================================================== */
/* Serialization */
/* ====================================================================== */
static inline size_t bound_serialize(void* dst, bound_t src)
{
#if defined(BOUND_NUM)
return num_serialize(dst,src);
#else
*(char*)dst = src->inf;
return num_serialize((char*)dst+1,bound_numref(src))+1;
#endif
}
static inline size_t bound_deserialize(bound_t dst, const void* src)
{
#if defined(BOUND_NUM)
return num_deserialize(dst,src);
#else
dst->inf = *(const char*)src;
return num_deserialize(bound_numref(dst),(const char*)src+1)+1;
#endif
}
static inline size_t bound_serialized_size(bound_t a)
{
#if defined(BOUND_NUM)
return num_serialized_size(a);
#else
return num_serialized_size(bound_numref(a))+1;
#endif
}
static inline size_t bound_serialize_array(void* dst, bound_t* src, size_t size)
{
size_t i,n=0;
for (i=0;i<size;i++)
n += bound_serialize((char*)dst+n,src[i]);
return n;
}
static inline size_t bound_deserialize_array(bound_t* dst, const void* src, size_t size)
{
size_t i,n=0;
for (i=0;i<size;i++)
n += bound_deserialize(dst[i],(const char*)src+n);
return n;
}
static inline size_t bound_serialized_size_array(bound_t* src, size_t size)
{
size_t i,n=0;
for (i=0;i<size;i++)
n += bound_serialized_size(src[i]);
return n;
}
#ifdef __cplusplus
}
#endif
#endif
|