The R Project SVN R

Rev

Rev 51702 | Rev 51790 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 51702 Rev 51781
Line 163... Line 163...
163
    R_PosInf = 1.0/R_Zero_Hack;
163
    R_PosInf = 1.0/R_Zero_Hack;
164
    R_NegInf = -1.0/R_Zero_Hack;
164
    R_NegInf = -1.0/R_Zero_Hack;
165
}
165
}
166
 
166
 
167
/* Keep these two in step */
167
/* Keep these two in step */
-
 
168
/* FIXME: consider using
-
 
169
    tmp = (LDOUBLE)x1 - floor(q) * (LDOUBLE)x2;
-
 
170
 */
168
static double myfmod(double x1, double x2)
171
static double myfmod(double x1, double x2)
169
{
172
{
170
    double q = x1 / x2, tmp;
173
    double q = x1 / x2, tmp;
171
 
174
 
172
    if (x2 == 0.0) return R_NaN;
175
    if (x2 == 0.0) return R_NaN;
Line 1517... Line 1520...
1517
	i1 = (++i1==n1) ? 0 : i1,				\
1520
	i1 = (++i1==n1) ? 0 : i1,				\
1518
	i2 = (++i2==n2) ? 0 : i2,				\
1521
	i2 = (++i2==n2) ? 0 : i2,				\
1519
	i3 = (++i3==n3) ? 0 : i3,				\
1522
	i3 = (++i3==n3) ? 0 : i3,				\
1520
	++i)
1523
	++i)
1521
 
1524
 
1522
static SEXP math3(SEXP sa, SEXP sb, SEXP sc,
-
 
1523
		  double (*f)(double, double, double), SEXP lcall)
-
 
1524
{
-
 
1525
    SEXP sy;
-
 
1526
    int i, ia, ib, ic, n, na, nb, nc;
-
 
1527
    double ai, bi, ci, *a, *b, *c, *y;
-
 
1528
    int naflag;
-
 
1529
 
-
 
1530
#define SETUP_Math3						\
1525
#define SETUP_Math3						\
1531
    if (!isNumeric(sa) || !isNumeric(sb) || !isNumeric(sc))	\
1526
    if (!isNumeric(sa) || !isNumeric(sb) || !isNumeric(sc))	\
1532
	errorcall(lcall, R_MSG_NONNUM_MATH);			\
1527
	errorcall(lcall, R_MSG_NONNUM_MATH);			\
1533
								\
1528
								\
1534
    na = LENGTH(sa);						\
1529
    na = LENGTH(sa);						\
Line 1547... Line 1542...
1547
    b = REAL(sb);						\
1542
    b = REAL(sb);						\
1548
    c = REAL(sc);						\
1543
    c = REAL(sc);						\
1549
    y = REAL(sy);						\
1544
    y = REAL(sy);						\
1550
    naflag = 0
1545
    naflag = 0
1551
 
1546
 
1552
    SETUP_Math3;
-
 
1553
 
-
 
1554
#ifdef R_MEMORY_PROFILING
-
 
1555
    if (RTRACE(sa) || RTRACE(sb) || RTRACE(sc)){
-
 
1556
       if (RTRACE(sa))
-
 
1557
	  memtrace_report(sa,sy);
-
 
1558
       else if (RTRACE(sb))
-
 
1559
	  memtrace_report(sb, sy);
-
 
1560
       else if (RTRACE(sc))
-
 
1561
	  memtrace_report(sc,sy);
-
 
1562
       SET_RTRACE(sy, 1);
-
 
1563
    }
-
 
1564
#endif
-
 
1565
 
-
 
1566
    mod_iterate3 (na, nb, nc, ia, ib, ic) {
-
 
1567
	ai = a[ia];
-
 
1568
	bi = b[ib];
-
 
1569
	ci = c[ic];
-
 
1570
	if_NA_Math3_set(y[i], ai,bi,ci)
-
 
1571
	else {
-
 
1572
	    y[i] = f(ai, bi, ci);
-
 
1573
	    if (ISNAN(y[i])) naflag = 1;
-
 
1574
	}
-
 
1575
    }
-
 
1576
 
-
 
1577
#define FINISH_Math3				\
1547
#define FINISH_Math3				\
1578
    if(naflag)					\
1548
    if(naflag)					\
1579
	warningcall(lcall, R_MSG_NA);		\
1549
	warningcall(lcall, R_MSG_NA);		\
1580
						\
1550
						\
1581
    if (n == na) {				\
1551
    if (n == na) {				\
Line 1585... Line 1555...
1585
	DUPLICATE_ATTRIB(sy, sb);	\
1555
	DUPLICATE_ATTRIB(sy, sb);	\
1586
    }						\
1556
    }						\
1587
    else if (n == nc) {				\
1557
    else if (n == nc) {				\
1588
	DUPLICATE_ATTRIB(sy, sc);	\
1558
	DUPLICATE_ATTRIB(sy, sc);	\
1589
    }						\
1559
    }						\
1590
    UNPROTECT(4)
-
 
1591
 
-
 
1592
    FINISH_Math3;
-
 
1593
 
-
 
1594
    return sy;
-
 
1595
} /* math3 */
-
 
1596
 
1560
 
1597
static SEXP math3_1(SEXP sa, SEXP sb, SEXP sc, SEXP sI,
1561
static SEXP math3_1(SEXP sa, SEXP sb, SEXP sc, SEXP sI,
1598
		    double (*f)(double, double, double, int), SEXP lcall)
1562
		    double (*f)(double, double, double, int), SEXP lcall)
1599
{
1563
{
1600
    SEXP sy;
1564
    SEXP sy;