Ejemplo n.º 1
0
void main() {

    int a, b;
    int * d = &globalVar;
    void * e = malloc(sizeof(int));
    d = (int*)e;
    a = nondet_int() * nondet_int();
    b = -7 * nondet_int();

    a = times2(a);
    a = times2(a);
    b = negate(b);

    *d = nondet_int();
    *d = negate(*d);

    if (a == 44 && b == 7)
    {
ERROR:
        return;
    }

    check(a);
    check(b);

    int c = a + b;
    c *= 2;
}
Ejemplo n.º 2
0
static cl_object
generate(cl_object digits, float_approx *approx)
{
        cl_object d, x;
        cl_fixnum digit;
        bool tc1, tc2;
        do {
                d = ecl_truncate2(ecl_times(approx->r, PRINT_BASE), approx->s);
                approx->r = VALUES(1);
                approx->mp = ecl_times(approx->mp, PRINT_BASE);
                approx->mm = ecl_times(approx->mm, PRINT_BASE);
                tc1 = approx->low_ok?
                        ecl_lowereq(approx->r, approx->mm) :
                        ecl_lower(approx->r, approx->mm);
                x = ecl_plus(approx->r, approx->mp);
                tc2 = approx->high_ok?
                        ecl_greatereq(x, approx->s) :
                        ecl_greater(x, approx->s);
                if (tc1 || tc2) {
                        break;
                }
                ecl_string_push_extend(digits, ecl_digit_char(ecl_fixnum(d), 10));
        } while (1);
        if (tc2 && !tc1) {
                digit = ecl_fixnum(d) + 1;
        } else if (tc1 && !tc2) {
                digit = ecl_fixnum(d);
        } else if (ecl_lower(times2(approx->r), approx->s)) {
                digit = ecl_fixnum(d);
        } else {
                digit = ecl_fixnum(d) + 1;
        }
        ecl_string_push_extend(digits, ecl_digit_char(digit, 10));
        return digits;
}
Ejemplo n.º 3
0
Lisp_Object Llcm(Lisp_Object nil, Lisp_Object a, Lisp_Object b)
{
    Lisp_Object g;
    push2(b, a);
    g = gcd(a, b);
    errexitn(2);
    pop(a);
    a = quot2(a, g);
    pop(b);
    errexit();
    a = times2(a, b);
    errexit();
    return onevalue(a);
}
Ejemplo n.º 4
0
static Lisp_Object plusir(Lisp_Object a, Lisp_Object b)
/*
 * fixnum and ratio, but also valid for bignum and ratio.
 * Note that if the inputs were in lowest terms there is no need for
 * and GCD calculations here.
 */
{
    Lisp_Object nil;
    push(b);
    a = times2(a, denominator(b));
    nil = C_nil;
    if (!exception_pending()) a = plus2(a, numerator(stack[0]));
    pop(b);
    errexit();
    return make_ratio(a, denominator(b));
}
Ejemplo n.º 5
0
int doit_times2()
{
  cudaFree(0);
  CHECK_CUDA_ERROR();

  int h_val[DIM];
  int h_result[DIM];

  for(int i = 0; i < DIM; ++i)
    h_val[i] = i;

  // Allocate device memory
  unsigned int size = sizeof(int) * DIM;
  int* d_val;
  cudaMalloc((void**)&d_val, size);
  CHECK_CUDA_ERROR();

  int* d_result;
  cudaMalloc((void**)&d_result, size);
  CHECK_CUDA_ERROR();

  // Send input to device
  cudaMemcpy(d_val, h_val, size, cudaMemcpyHostToDevice);
  CHECK_CUDA_ERROR();

  // Call the kernel wrapper
  times2(d_val, d_result, DIM);
  CHECK_CUDA_ERROR();

  // Get back results
  cudaMemcpy(h_result, d_result, size, cudaMemcpyDeviceToHost);
  CHECK_CUDA_ERROR();

  for(int i = 0; i < DIM; ++i)
    printf("%d ^ 2 = %d\n", h_val[i], h_result[i]);

  // Free memory
  cudaFree((void*)d_val);
  CHECK_CUDA_ERROR();

  cudaFree((void*)d_result);
  CHECK_CUDA_ERROR();

  return 0;
}
Ejemplo n.º 6
0
static float_approx *
setup(cl_object number, float_approx *approx)
{
        cl_object f = cl_integer_decode_float(number);
        cl_fixnum e = ecl_fixnum(VALUES(1)), min_e;
        bool limit_f = 0;
        switch (ecl_t_of(number)) {
        case t_singlefloat:
                min_e = FLT_MIN_EXP;
                limit_f = (number->SF.SFVAL ==
                           ldexpf(FLT_RADIX, FLT_MANT_DIG-1));
                break;
        case t_doublefloat:
                min_e = DBL_MIN_EXP;
                limit_f = (number->DF.DFVAL ==
                           ldexp(FLT_RADIX, DBL_MANT_DIG-1));
                break;
#ifdef ECL_LONG_FLOAT
        case t_longfloat:
                min_e = LDBL_MIN_EXP;
                limit_f = (number->longfloat.value ==
                           ldexpl(FLT_RADIX, LDBL_MANT_DIG-1));
#endif
        }
        approx->low_ok = approx->high_ok = ecl_evenp(f);
        if (e > 0) {
                cl_object be = EXPT_RADIX(e);
                if (limit_f) {
                        cl_object be1 = ecl_times(be, ecl_make_fixnum(FLT_RADIX));
                        approx->r = times2(ecl_times(f, be1));
                        approx->s = ecl_make_fixnum(FLT_RADIX*2);
                        approx->mm = be;
                        approx->mp = be1;
                } else {
                        approx->r = times2(ecl_times(f, be));
                        approx->s = ecl_make_fixnum(2);
                        approx->mm = be;
                        approx->mp = be;
                }
        } else if (!limit_f || (e == min_e)) {
                approx->r = times2(f);
                approx->s = times2(EXPT_RADIX(-e));
                approx->mp = ecl_make_fixnum(1);
                approx->mm = ecl_make_fixnum(1);
        } else {
                approx->r = times2(ecl_make_fixnum(FLT_RADIX));
                approx->s = times2(EXPT_RADIX(1-e));
                approx->mp = ecl_make_fixnum(FLT_RADIX);
                approx->mm = ecl_make_fixnum(1);
        }
        return approx;
}
Ejemplo n.º 7
0
static Lisp_Object plusrr(Lisp_Object a, Lisp_Object b)
/*
 * Adding two ratios involves some effort to keep the result in
 * lowest terms.
 */
{
    Lisp_Object nil = C_nil;
    Lisp_Object na = numerator(a), nb = numerator(b);
    Lisp_Object da = denominator(a), db = denominator(b);
    Lisp_Object w = nil;
    push5(na, nb, da, db, nil);
#define g   stack[0]
#define db  stack[-1]
#define da  stack[-2]
#define nb  stack[-3]
#define na  stack[-4]
    g = gcd(da, db);
    nil = C_nil;
    if (exception_pending()) goto fail;
/*
 * all the calls to quot2() in this procedure are expected - nay required -
 * to give exact integer quotients.
 */
    db = quot2(db, g);
    nil = C_nil;
    if (exception_pending()) goto fail;
    g = quot2(da, g);
    nil = C_nil;
    if (exception_pending()) goto fail;
    na = times2(na, db);
    nil = C_nil;
    if (exception_pending()) goto fail;
    nb = times2(nb, g);
    nil = C_nil;
    if (exception_pending()) goto fail;
    na = plus2(na, nb);
    nil = C_nil;
    if (exception_pending()) goto fail;
    da = times2(da, db);
    nil = C_nil;
    if (exception_pending()) goto fail;
    g = gcd(na, da);
    nil = C_nil;
    if (exception_pending()) goto fail;
    na = quot2(na, g);
    nil = C_nil;
    if (exception_pending()) goto fail;
    da = quot2(da, g);
    nil = C_nil;
    if (exception_pending()) goto fail;
    w = make_ratio(na, da);
/*
 * All the goto statements and the label seem a fair way of expressing
 * the common action that has to be taken if an error or interrupt is
 * detected during any of the intermediate steps here.  Anyone who
 * objects can change it if they really want...
 */
fail:
    popv(5);
    return w;
#undef na
#undef nb
#undef da
#undef db
#undef g
}