58 # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
59 # define CURRENT_FUNCTION __func__
61 # if defined(__GNUC__)
62 # define CURRENT_FUNCTION __FUNCTION__
64 # define CURRENT_FUNCTION "<unknown>"
68 #define PUSH_TIMEOUT_ENV(env) \
69 push_timeout_env(env, CURRENT_FUNCTION, __FILE__, __LINE__)
71 #define POP_TIMEOUT_ENV(env) \
72 pop_timeout_env(env, CURRENT_FUNCTION, __FILE__, __LINE__)
74 #define PUSH_TIMEOUT(delay) \
75 push_timeout(delay, CURRENT_FUNCTION, __FILE__, __LINE__)
77 #define POP_TIMEOUT() \
78 pop_timeout(CURRENT_FUNCTION, __FILE__, __LINE__)
89 #ifndef __LONG_LONG_MAX__
90 #define __LONG_LONG_MAX__ 9223372036854775807LL
93 #define LONG_LONG_MAX __LONG_LONG_MAX__
95 #define LONG_LONG_MIN (-LONG_LONG_MAX-1)
97 #define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1)
110 #if defined(LINEAR_VALUE_IS_INT128)
112 #error "not implemented yet"
114 #include <inttypes.h>
115 #define LINEAR_VALUE_STRING "int128"
116 typedef __int128
Value;
117 #define VALUE_FMT "???"
118 #define VALUE_CONST(val) (val##LLL)
119 #define VALUE_NAN ???_MIN
123 #define VALUE_MIN (???_MIN+1LL)
124 #define VALUE_MAX ???_MAX
125 #if defined(LINEAR_VALUE_ASSUME_SOFTWARE_IDIV) && \
126 defined(__SIZEOF_???__) && \
128 #error "long long is expected to be 64-bit to use software idiv"
130 #define VALUE_SQRT_MIN ???LLL
131 #define VALUE_SQRT_MAX -???LLL
132 #define VALUE_ZERO (0LLL)
133 #define VALUE_ONE (1LLL)
134 #define VALUE_MONE (-1LLL)
137 #define VALUE_TO_LONG(val) \
138 ((long)((val)>(Value)LONG_MIN&&(val)<=(Value)LONG_MAX)?\
139 (val):(THROW(overflow_error), LONG_MIN))
140 #define VALUE_TO_INT(val) \
141 ((int)((val)>(Value)INT_MIN&&(val)<=(Value)INT_MAX)?\
142 (val):(THROW(overflow_error), INT_MIN))
143 #define VALUE_TO_DOUBLE(val) ((double)(val))
144 #define VALUE_TO_FLOAT(val) ((float)((int)(val)))
159 #elif defined(LINEAR_VALUE_IS_LONGLONG)
160 #define LINEAR_VALUE_STRING "long long int"
161 typedef long long int Value;
162 #define VALUE_FMT "%lld"
163 #define VALUE_CONST(val) (val##LL)
164 #define VALUE_NAN LONG_LONG_MIN
168 #define VALUE_MIN (LONG_LONG_MIN+1LL)
169 #define VALUE_MAX LONG_LONG_MAX
170 #if defined(LINEAR_VALUE_ASSUME_SOFTWARE_IDIV) && \
171 defined(__SIZEOF_LONG_LONG__) && \
172 __SIZEOF_LONG_LONG__ != 8
173 #error "long long is expected to be 64-bit to use software idiv"
175 #define VALUE_SQRT_MIN 3037000499LL
176 #define VALUE_SQRT_MAX -3037000499LL
177 #define VALUE_ZERO (0LL)
178 #define VALUE_ONE (1LL)
179 #define VALUE_MONE (-1LL)
182 #define VALUE_TO_LONG(val) \
183 ((long)((val)>(Value)LONG_MIN&&(val)<=(Value)LONG_MAX)?\
184 (val):(THROW(overflow_error), LONG_MIN))
185 #define VALUE_TO_INT(val) \
186 ((int)((val)>(Value)INT_MIN&&(val)<=(Value)INT_MAX)?\
187 (val):(THROW(overflow_error), INT_MIN))
188 #define VALUE_TO_DOUBLE(val) ((double)(val))
191 #define VALUE_TO_FLOAT(val) ((float)((int)(val)))
206 #elif defined(LINEAR_VALUE_IS_LONG)
207 #define LINEAR_VALUE_STRING "long int"
209 #define VALUE_FMT "%ld"
210 #define VALUE_CONST(val) (val##L)
211 #define VALUE_NAN LONG_MIN
212 #define VALUE_MIN (LONG_MIN+1L)
213 #define VALUE_MAX LONG_MAX
214 #define VALUE_ZERO 0L
216 #define VALUE_MONE -1L
217 #define VALUE_TO_LONG(val) (val)
218 #define VALUE_TO_INT(val) ((int)(val))
219 #define VALUE_TO_FLOAT(val) ((float)(val))
220 #define VALUE_TO_DOUBLE(val) ((double)(val))
266 #elif defined(LINEAR_VALUE_IS_CHARS)
267 #define LINEAR_VALUE_STRING "chars..."
268 typedef union {
char *s;
long l;
int i;
float f;
double d;}
Value;
269 #define VALUE_FMT "%s"
270 #define VALUE_CONST(val) ((Value)(val))
271 #define VALUE_NAN ((Value)(long)0xdadeebee)
272 #define VALUE_MIN ((Value)(long)0xdeadbeef)
273 #define VALUE_MAX ((Value)(long)0xfeedabee)
274 #define VALUE_ZERO ((Value)0)
275 #define VALUE_ONE ((Value)1)
276 #define VALUE_MONE ((Value)-1)
277 #define VALUE_TO_LONG(val) (val.l)
278 #define VALUE_TO_INT(val) (val.i)
279 #define VALUE_TO_FLOAT(val) (val.f)
280 #define VALUE_TO_DOUBLE(val) (val.d)
295 #define LINEAR_VALUE_STRING "int"
297 #define VALUE_FMT "%d"
298 #define VALUE_CONST(val) (val)
299 #define VALUE_NAN INT_MIN
300 #define VALUE_MIN (INT_MIN+1)
301 #define VALUE_MAX INT_MAX
304 #define VALUE_MONE -1
305 #define VALUE_TO_LONG(val) ((long)(val))
306 #define VALUE_TO_INT(val) ((int)(val))
307 #define VALUE_TO_FLOAT(val) ((float)(val))
308 #define VALUE_TO_DOUBLE(val) ((double)(val))
317 #define int_to_value(i) ((Value)(i))
318 #define long_to_value(l) ((Value)(l))
319 #define float_to_value(f) ((Value)(f))
320 #define double_to_value(d) ((Value)(d))
324 #define value_eq(v1,v2) ((v1)==(v2))
325 #define value_ne(v1,v2) ((v1)!=(v2))
326 #define value_gt(v1,v2) ((v1)>(v2))
327 #define value_ge(v1,v2) ((v1)>=(v2))
328 #define value_lt(v1,v2) ((v1)<(v2))
329 #define value_le(v1,v2) ((v1)<=(v2))
333 #define value_sign(v) (value_eq(v,VALUE_ZERO)?0:value_lt(v,VALUE_ZERO)?-1:1)
334 #define value_compare(v1,v2) (value_eq(v1,v2)?0:value_lt(v1,v2)?-1:1)
342 #define value_plus(v1,v2) ((v1)+(v2))
343 #define value_div(v1,v2) ((v1)/(v2))
344 #define value_mod(v1,v2) ((v1)%(v2))
345 #define value_direct_multiply(v1,v2) ((v1)*(v2))
346 #define value_minus(v1,v2) ((v1)-(v2))
347 #define value_pdiv(v1,v2) (divide(v1,v2))
348 #define value_pmod(v1,v2) (modulo(v1,v2))
349 #define value_min(v1,v2) (value_le(v1,v2)? (v1): (v2))
350 #define value_max(v1,v2) (value_ge(v1,v2)? (v1): (v2))
351 #define value_or(v1,v2) ((v1)|(v2))
352 #define value_and(v1,v2) ((v1)&(v2))
353 #define value_lshift(v1,v2) ((v1)<<(v2))
354 #define value_rshift(v1,v2) ((v1)>>(v2))
358 #define value_assign(ref,val) (ref=(val))
359 #define value_addto(ref,val) (ref+=(val))
360 #define value_increment(ref) (ref++)
361 #define value_direct_product(ref,val) (ref*=(val))
362 #define value_multiply(ref,val) value_assign(ref,value_mult(ref,val))
363 #define value_substract(ref,val) (ref-=(val))
364 #define value_decrement(ref) (ref--)
365 #define value_division(ref,val) (ref/=(val))
366 #define value_modulus(ref,val) (ref%=(val))
367 #define value_pdivision(ref,val) value_assign(ref,value_pdiv(ref,val))
368 #define value_oppose(ref) value_assign(ref,value_uminus(ref))
369 #define value_absolute(ref) value_assign(ref,value_abs(ref))
370 #define value_minimum(ref,val) value_assign(ref,value_min(ref,val))
371 #define value_maximum(ref,val) value_assign(ref,value_max(ref,val))
372 #define value_orto(ref,val) (ref |= (val))
373 #define value_andto(ref,val) (ref &= (val))
377 #define value_uminus(val) (-(val))
378 #define value_not(val) (~(val))
379 #define value_abs(val) \
380 ((value_posz_p(val) ? (val) : \
381 (value_ne((val), VALUE_NAN) ? value_uminus(val) : \
382 (THROW (overflow_error), VALUE_NAN ))))
384 #define value_pos_p(val) value_gt(val,VALUE_ZERO)
385 #define value_neg_p(val) value_lt(val,VALUE_ZERO)
386 #define value_posz_p(val) value_ge(val,VALUE_ZERO)
387 #define value_negz_p(val) value_le(val,VALUE_ZERO)
388 #define value_zero_p(val) value_eq(val,VALUE_ZERO)
391 #define value_notzero_p(val) value_ne(val,VALUE_ZERO)
392 #define value_one_p(val) value_eq(val,VALUE_ONE)
393 #define value_notone_p(val) value_ne(val,VALUE_ONE)
394 #define value_mone_p(val) value_eq(val,VALUE_MONE)
395 #define value_notmone_p(val) value_ne(val,VALUE_MONE)
396 #define value_min_p(val) value_eq(val,VALUE_MIN)
397 #define value_max_p(val) value_eq(val,VALUE_MAX)
398 #define value_notmin_p(val) value_ne(val,VALUE_MIN)
399 #define value_notmax_p(val) value_ne(val,VALUE_MAX)
408 #define value_protected_hard_idiv_multiply(v,w,throw) \
409 ((value_zero_p(w) || value_zero_p(v))? VALUE_ZERO: \
410 value_lt(value_abs(v),value_div(VALUE_MAX,value_abs(w)))? \
411 value_direct_multiply(v,w): (throw, VALUE_NAN))
415 #if defined(LINEAR_VALUE_ASSUME_SOFTWARE_IDIV)
416 #define value_protected_multiply(v,w,throw) \
417 ((value_le(v,VALUE_SQRT_MAX) && value_le(w,VALUE_SQRT_MAX) && \
418 value_ge(v,VALUE_SQRT_MIN) && value_ge(w,VALUE_SQRT_MIN))? \
419 value_direct_multiply(v,w): value_protected_hard_idiv_multiply(v,w,throw))
421 #define value_protected_multiply(v,w,throw) \
422 value_protected_hard_idiv_multiply(v,w,throw)
427 #define value_protected_mult(v,w) \
428 value_protected_multiply(v,w,THROW(overflow_error))
429 #define value_protected_product(v,w) \
430 v=value_protected_mult(v,w)
435 #if defined(LINEAR_VALUE_PROTECT_MULTIPLY)
436 #define value_mult(v,w) value_protected_mult(v,w)
437 #define value_product(v,w) value_protected_product(v,w)
444 #define value_mult(v,w) \
445 value_protected_multiply(v,w, \
446 (fprintf(stderr,"[value_mult] value overflow!\n"),THROW(overflow_error)))
447 #define value_product(v,w) v=value_mult(v,w)
462 #if defined(LINEAR_VALUE_IS_CHARS)
463 #define value_fake_binary(v1,v2) ((Value)((v1).i+(v2).i))
464 #define value_bool_binary(v1,v2) ((int)((v1).i+(v2).i))
465 #undef float_to_value
466 #define float_to_value(f) ((Value)f)
467 #undef double_to_value
468 #define double_to_value(f) ((Value)f)
470 #define value_uminus(v) (v)
472 #define value_mult(v1,v2) value_fake_binary(v1,v2)
474 #define value_mod(v1,v2) value_fake_binary(v1,v2)
476 #define value_ge(v1,v2) value_bool_binary(v1,v2)
478 #define value_gt(v1,v2) value_bool_binary(v1,v2)
480 #define value_le(v1,v2) value_bool_binary(v1,v2)
482 #define value_lt(v1,v2) value_bool_binary(v1,v2)
484 #define value_ne(v1,v2) value_bool_binary(v1,v2)
486 #define value_eq(v1,v2) value_bool_binary(v1,v2)
488 #define value_plus(v1,v2) value_fake_binary(v1,v2)
490 #define value_minus(v1,v2) value_fake_binary(v1,v2)
492 #define value_pdiv(v1,v2) value_fake_binary(v1,v2)
494 #define value_div(v1,v2) value_fake_binary(v1,v2)
496 #define value_mod(v1,v2) value_fake_binary(v1,v2)
498 #define value_addto(v1,v2) value_assign(v1,value_plus(v1,v2))
499 #undef value_substract
500 #define value_substract(v1,v2) value_addto(v1,v2)
502 #define value_product(v1,v2) value_addto(v1,v2)
504 #define value_modulus(v1,v2) value_addto(v1,v2)
505 #undef value_division
506 #define value_division(v1,v2) value_addto(v1,v2)
507 #undef value_increment
508 #define value_increment(v) value_addto(v,VALUE_ONE)
509 #undef value_decrement
510 #define value_decrement(v) value_addto(v,VALUE_MONE)
512 #define value_orto(ref,val) value_addto(v1,v2)
514 #define value_andto(ref,val) value_addto(v1,v2)
516 #define value_or(v1,v2) value_fake_binary(v1,v2)
518 #define value_and(v1,v2) value_fake_binary(v1,v2)
520 #define value_lshift(v1,v2) value_fake_binary(v1,v2)
522 #define value_rshift(v1,v2) value_fake_binary(v1,v2)
529 #define ABS(x) (((x)>=0) ? (x) : -(x))
537 #define MIN(x,y) (((x)>=(y))?(y):(x))
540 #define MAX(x,y) (((x)>=(y))?(x):(y))
544 #define SIGN(x) (((x)>0)? 1 : ((x)==0? 0 : -1))
552 #define DIVIDE(x,y) ((y)>0? POSITIVE_DIVIDE(x,y) : \
553 -POSITIVE_DIVIDE((x),(-(y))))
556 #define POSITIVE_DIVIDE(x,y) ((x)>0 ? (x)/(y) : - (-(x)+(y)-1)/(y))
559 #define MODULO(x,y) ((y)>0 ? POSITIVE_MODULO(x,y) : POSITIVE_MODULO(-x,-y))
567 #define POSITIVE_MODULO(x,y) ((x) > 0 ? (x)%(y) : \
568 ((x)%(y) == 0 ? 0 : ((y)-(-(x))%(y))))
574 #define pgcd(a,b) pgcd_slow(a,b)
576 #define divide(a,b) DIVIDE(a,b)
578 #define modulo(a,b) MODULO(a,b)
588 #ifndef _has_yy_size_t
589 #define _has_yy_size_t
void __attribute__((weak, noreturn)) throw_exception(const int
void throw_exception(const int, const char *, const char *, const int)
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])