コード例 #1
0
ファイル: cxhypb.c プロジェクト: billw2012/BGalaxy1
struct cxpr
cxacosh (struct cxpr z)
{
  struct cxpr w;
  struct xpr ls, rs;

  w = cxsqrt (cxsub (cxsqr (z), cxOne));
  ls = cxabs (cxsum (z, w));
  rs = xmul (xVSV, cxabs (z));
  if (xprcmp (&ls, &rs) < 0)
    return cxneg (cxlog (cxsub (z, w)));
  else
    return cxlog (cxsum (z, w));
}
コード例 #2
0
ファイル: cxhypb.c プロジェクト: billw2012/BGalaxy1
struct cxpr
cxsinh (struct cxpr z)
{
  struct cxpr w;

  w = cxsub (cxexp (z), cxexp (cxneg (z)));
  w.re = xpr2 (w.re, -1);
  w.im = xpr2 (w.im, -1);
  return w;
}
コード例 #3
0
ファイル: cxhypb.c プロジェクト: billw2012/BGalaxy1
struct cxpr
cxasinh (struct cxpr z)
{
  struct cxpr w;
  struct xpr ls, rs;

  /* In this way, cxasinh() works fine also with real numbers */
  /* very near to -oo.                                       */
  w = cxsqrt (cxsum (cxOne, cxsqr (z)));
  ls = cxabs (cxsum (z, w));
  rs = xmul (xVSV, cxabs (z));
  if (xprcmp (&ls, &rs) < 0)
    return cxneg (cxlog (cxsub (w, z)));
  else
    return cxlog (cxsum (z, w));
}
コード例 #4
0
ファイル: cxhypb.c プロジェクト: billw2012/BGalaxy1
struct cxpr
cxatanh (struct cxpr z)
{
  struct cxpr w;
  struct xpr t;
  int errcond;

  t = xadd (xabs (z.re), xOne, 1);
  errcond = xsgn (&z.im) == 0 && xsgn (&t) == 0;
  if (xsigerr (errcond, XEDOM, "cxatanh()"))
    return cxZero;
  else
    {
      w = cxdiv (cxsum (cxOne, z), cxsub (cxOne, z));
      w = cxlog_sqrt (w);
      return w;
    }
}
コード例 #5
0
ファイル: dssprintf.c プロジェクト: ISLEcode/kornshell
static int
getfmt(Sfio_t* sp, void* vp, Sffmt_t* dp)
{
	register Fmt_t*	fp = (Fmt_t*)dp;
	register Arg_t*	ap = fp->ap++;
	Value_t*	value = (Value_t*)vp;
	Cxoperand_t	ret;

	if (ap->expr && cxeval(fp->cx, ap->expr, fp->data, &ret) < 0 || cxcast(fp->cx, &ret, ap->variable, ap->cast, fp->data, ap->details))
	{
		fp->errors++;
		return -1;
	}
	fp->fmt.flags |= SFFMT_VALUE;
	switch (ap->type)
	{
	case DSS_FORMAT_char:
		fp->fmt.size = sizeof(int);
		if (ret.value.number < 1)
			value->c = 0;
		else if (ret.value.number > UCHAR_MAX)
			value->c = UCHAR_MAX;
		else
			value->c = (unsigned char)ret.value.number;
		break;
	case DSS_FORMAT_float:
		fp->fmt.size = sizeof(double);
		value->f = ret.value.number;
		break;
	case DSS_FORMAT_int:
#if 0
		/*
		 * this code is technically correct but overly
		 * complicates script portability between architectures
		 * with differing sizeof(int) and/or sizeof(long)
		 */

		fp->fmt.size = sizeof(int);
		if (((ret.value.number >= 0) ? ret.value.number : -ret.value.number) < 1)
			value->i = 0;
		else if (ret.value.number > UINT_MAX)
			value->i = INT_MAX;
		else if (ret.value.number < INT_MIN)
			value->i = INT_MAX;
		else
			value->i = (unsigned int)ret.value.number;
		break;
#endif
	case DSS_FORMAT_long:
		fp->fmt.size = sizeof(Sflong_t);
		if (((ret.value.number >= 0) ? ret.value.number : -ret.value.number) < 1)
			value->q = 0;
		else if (ret.value.number > FLTMAX_UINTMAX_MAX)
			value->q = FLTMAX_INTMAX_MAX;
		else if (ret.value.number < FLTMAX_INTMAX_MIN)
			value->q = FLTMAX_INTMAX_MAX;
		else
			value->q = (Sfulong_t)((Sflong_t)ret.value.number);
		break;
	case DSS_FORMAT_string:
		if (ap->fmt & (FMT_EXP_CHAR|FMT_EXP_LINE|FMT_EXP_NOCR|FMT_EXP_NONL|FMT_EXP_WIDE))
			ret.value.string.size = strexp(ret.value.string.data, ap->fmt);
		if (ap->edit)
			cxsub(fp->cx, ap->edit, &ret);
		if (ap->flags & DSS_FORMAT_quote)
			ret.value.string.size = strlen(ret.value.string.data = fmtquote(ret.value.string.data, ap->qb, ap->qe, ret.value.string.size, ap->fmt));
		value->s = ret.value.string.data;
		fp->fmt.size = ret.value.string.size;
		break;
	}
	return 0;
}