コード例 #1
0
ファイル: bignum.c プロジェクト: bnoordhuis/suv
sexp sexp_complex_exp (sexp ctx, sexp z) {
  double e2x = exp(sexp_to_double(sexp_complex_real(z))),
    y = sexp_to_double(sexp_complex_imag(z));
  sexp_gc_var1(res);
  sexp_gc_preserve1(ctx, res);
  res = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO);
  sexp_complex_real(res) = sexp_make_flonum(ctx, e2x*cos(y));
  sexp_complex_imag(res) = sexp_make_flonum(ctx, e2x*sin(y));
  sexp_gc_release1(ctx);
  return res;
}
コード例 #2
0
ファイル: bignum.c プロジェクト: bnoordhuis/suv
sexp sexp_complex_cos (sexp ctx, sexp z) {
  double x = sexp_to_double(sexp_complex_real(z)),
    y = sexp_to_double(sexp_complex_imag(z));
  sexp_gc_var1(res);
  sexp_gc_preserve1(ctx, res);
  res = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO);
  sexp_complex_real(res) = sexp_make_flonum(ctx, cos(x)*cosh(y));
  sexp_complex_imag(res) = sexp_make_flonum(ctx, -sin(x)*sinh(y));
  sexp_gc_release1(ctx);
  return res;
}
コード例 #3
0
ファイル: bignum.c プロジェクト: bnoordhuis/suv
sexp sexp_complex_log (sexp ctx, sexp z) {
  double x = sexp_to_double(sexp_complex_real(z)),
    y = sexp_to_double(sexp_complex_imag(z));
  sexp_gc_var1(res);
  sexp_gc_preserve1(ctx, res);
  res = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO);
  sexp_complex_real(res) = sexp_make_flonum(ctx, log(sqrt(x*x + y*y)));
  sexp_complex_imag(res) = sexp_make_flonum(ctx, atan2(y, x));
  sexp_gc_release1(ctx);
  return res;
}
コード例 #4
0
ファイル: bignum.c プロジェクト: bnoordhuis/suv
sexp sexp_complex_sqrt (sexp ctx, sexp z) {
  double x = sexp_to_double(sexp_complex_real(z)),
    y = sexp_to_double(sexp_complex_imag(z)), r;
  sexp_gc_var1(res);
  sexp_gc_preserve1(ctx, res);
  r = sqrt(x*x + y*y);
  res = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO);
  sexp_complex_real(res) = sexp_make_flonum(ctx, sqrt((x+r)/2));
  sexp_complex_imag(res) = sexp_make_flonum(ctx, (y<0?-1:1)*sqrt((-x+r)/2));
  sexp_gc_release1(ctx);
  return res;
}
コード例 #5
0
ファイル: time.c プロジェクト: HotHat/chibi-scheme
sexp sexp_current_clock_second (sexp ctx, sexp self, sexp_sint_t n) {
#ifndef PLAN9
  struct timeval tv;
  struct timezone tz;
  if (gettimeofday(&tv, &tz))
    return sexp_user_exception(ctx, self, "couldn't gettimeofday", SEXP_FALSE);
  return sexp_make_flonum(ctx, tv.tv_sec + tv.tv_usec / 1000000.0);
#else
  time_t res = time(NULL);
  return sexp_make_flonum(ctx, res);
#endif
}
コード例 #6
0
ファイル: rand.c プロジェクト: mrb/chibi-scheme-mirror
static sexp sexp_rs_random_real (sexp ctx, sexp self, sexp_sint_t n, sexp rs) {
  int32_t res;
  if (! sexp_random_source_p(rs))
    return sexp_type_exception(ctx, self, rs_type_id, rs);
  sexp_call_random(rs, res);
  return sexp_make_flonum(ctx, (double)res / (double)RAND_MAX);
}
コード例 #7
0
ファイル: bignum.c プロジェクト: bnoordhuis/suv
sexp sexp_complex_acos (sexp ctx, sexp z) {
  sexp_gc_var2(res, tmp);
  sexp_gc_preserve2(ctx, res, tmp);
  res = sexp_complex_asin(ctx, z);
  tmp = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO);
  sexp_complex_real(tmp) = sexp_make_flonum(ctx, acos(-1)/2);
  res = sexp_sub(ctx, tmp, res);
  sexp_gc_release2(ctx);
  return res;
}
コード例 #8
0
ファイル: time.c プロジェクト: HotHat/chibi-scheme
sexp sexp_current_ntp_clock_values (sexp ctx, sexp self, sexp_sint_t n) {
  double second;
  int leap_second_indicator;
  sexp_gc_var3(res, car, cdr);
  current_ntp_clock_values (&second, &leap_second_indicator);
  sexp_gc_preserve3(ctx, res, car, cdr);
  cdr = sexp_make_boolean(leap_second_indicator);
  car = sexp_make_flonum(ctx, second);
  res = sexp_cons(ctx, car, cdr);
  sexp_gc_release3(ctx);
  return res;
}
コード例 #9
0
ファイル: time.c プロジェクト: mnieper/chibi-scheme
sexp sexp_current_clock_second (sexp ctx, sexp self, sexp_sint_t n) {
#ifdef _WIN32
  ULONGLONG t;
  SYSTEMTIME st;
  FILETIME ft;
  ULARGE_INTEGER uli;
  GetLocalTime(&st);
  (void) SystemTimeToFileTime(&st, &ft);
  /* Convert Win32 FILETIME to UNIX time */
  uli.LowPart = ft.dwLowDateTime;
  uli.HighPart = ft.dwHighDateTime;
  t = uli.QuadPart - (11644473600LL * 10 * 1000 * 1000);
  return sexp_make_flonum(ctx, ((double)t / (10 * 1000 * 1000)));
#elif !defined(PLAN9)
  struct timeval tv;
  struct timezone tz;
  if (gettimeofday(&tv, &tz))
    return sexp_user_exception(ctx, self, "couldn't gettimeofday", SEXP_FALSE);
  return sexp_make_flonum(ctx, tv.tv_sec + tv.tv_usec / 1000000.0);
#else
  time_t res = time(NULL);
  return sexp_make_flonum(ctx, res);
#endif
}
コード例 #10
0
ファイル: bignum.c プロジェクト: bnoordhuis/suv
sexp sexp_complex_atan (sexp ctx, sexp z) {
  sexp_gc_var3(res, tmp1, tmp2);
  sexp_gc_preserve3(ctx, res, tmp1, tmp2);
  tmp1 = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ONE);
  tmp1 = sexp_complex_mul(ctx, z, tmp1);
  res = sexp_make_complex(ctx, SEXP_ONE, SEXP_ZERO);
  res = sexp_complex_sub(ctx, res, tmp1);
  res = sexp_complex_log(ctx, res);
  tmp2 = sexp_make_complex(ctx, SEXP_ONE, SEXP_ZERO);
  tmp2 = sexp_complex_add(ctx, tmp2, tmp1);
  tmp2 = sexp_complex_log(ctx, tmp2);
  res = sexp_complex_sub(ctx, res, tmp2);
  tmp1 = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ONE);
  sexp_complex_imag(tmp1) = sexp_make_flonum(ctx, 0.5);
  res = sexp_complex_mul(ctx, res, tmp1);
  sexp_gc_release3(ctx);
  return res;
}
コード例 #11
0
ファイル: bignum.c プロジェクト: bnoordhuis/suv
static sexp sexp_to_complex (sexp ctx, sexp x) {
#if SEXP_USE_RATIOS
  sexp_gc_var1(tmp);
#endif
  if (sexp_flonump(x) || sexp_fixnump(x) || sexp_bignump(x)) {
    return sexp_make_complex(ctx, x, SEXP_ZERO);
#if SEXP_USE_RATIOS
  } else if (sexp_ratiop(x)) {
    sexp_gc_preserve1(ctx, tmp);
    tmp = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO);
    sexp_complex_real(tmp) = sexp_make_flonum(ctx, sexp_to_double(x));
    sexp_gc_release1(ctx);
    return tmp;
#endif
  } else {
    return x;
  }
}