The R Project SVN R

Rev

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

Rev 51267 Rev 51270
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1995, 1996, 1997  Robert Gentleman and Ross Ihaka
3
 *  Copyright (C) 1995, 1996, 1997  Robert Gentleman and Ross Ihaka
4
 *  Copyright (C) 1998--2007	    The R Development Core Team.
4
 *  Copyright (C) 1998--2010	    The R Development Core Team.
5
 *  Copyright (C) 2003-4	    The R Foundation
5
 *  Copyright (C) 2003-4	    The R Foundation
6
 *
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  the Free Software Foundation; either version 2 of the License, or
Line 1005... Line 1005...
1005
    case 20: return MATH1(cos);
1005
    case 20: return MATH1(cos);
1006
    case 21: return MATH1(sin);
1006
    case 21: return MATH1(sin);
1007
    case 22: return MATH1(tan);
1007
    case 22: return MATH1(tan);
1008
    case 23: return MATH1(acos);
1008
    case 23: return MATH1(acos);
1009
    case 24: return MATH1(asin);
1009
    case 24: return MATH1(asin);
-
 
1010
    case 25: return MATH1(atan);
1010
 
1011
 
1011
    case 30: return MATH1(cosh);
1012
    case 30: return MATH1(cosh);
1012
    case 31: return MATH1(sinh);
1013
    case 31: return MATH1(sinh);
1013
    case 32: return MATH1(tanh);
1014
    case 32: return MATH1(tanh);
1014
    case 33: return MATH1(acosh);
1015
    case 33: return MATH1(acosh);
Line 1031... Line 1032...
1031
	errorcall(call, _("unimplemented real function of 1 argument"));
1032
	errorcall(call, _("unimplemented real function of 1 argument"));
1032
    }
1033
    }
1033
    return s; /* never used; to keep -Wall happy */
1034
    return s; /* never used; to keep -Wall happy */
1034
}
1035
}
1035
 
1036
 
-
 
1037
/* methods are allowed to have more than one arg */
1036
SEXP attribute_hidden do_trunc(SEXP call, SEXP op, SEXP args, SEXP env)
1038
SEXP attribute_hidden do_trunc(SEXP call, SEXP op, SEXP args, SEXP env)
1037
{
1039
{
1038
    SEXP s;
1040
    SEXP s;
1039
    if (DispatchGroup("Math", call, op, args, env, &s))
1041
    if (DispatchGroup("Math", call, op, args, env, &s))
1040
	return s;
1042
	return s;
1041
    checkArity(op, args);
1043
    checkArity(op, args); /* but is -1 in names.c */
1042
    if (isComplex(CAR(args)))
1044
    if (isComplex(CAR(args)))
1043
	errorcall(call, _("unimplemented complex function"));
1045
	errorcall(call, _("unimplemented complex function"));
1044
    return math1(CAR(args), trunc, call);
1046
    return math1(CAR(args), trunc, call);
1045
}
1047
}
1046
 
1048
 
1047
/* FIXME: why did this check arity only for the default method? */
-
 
1048
/*
1049
/*
1049
   Note that this is slightly different from the do_math1 set, 
1050
   Note that this is slightly different from the do_math1 set, 
1050
   both for integer/logical inputs and what it dispatches to for complex ones.
1051
   both for integer/logical inputs and what it dispatches to for complex ones.
1051
*/
1052
*/
1052
 
1053
 
Line 1309... Line 1310...
1309
		  _("unimplemented real function of %d numeric arguments"), 2);
1310
		  _("unimplemented real function of %d numeric arguments"), 2);
1310
    }
1311
    }
1311
    return op;			/* never used; to keep -Wall happy */
1312
    return op;			/* never used; to keep -Wall happy */
1312
}
1313
}
1313
 
1314
 
1314
/* FIXME: this could be merged with do_math1 now
-
 
1315
   and why does it not check arity before dispatch? */
-
 
1316
SEXP attribute_hidden do_atan(SEXP call, SEXP op, SEXP args, SEXP env)
-
 
1317
{
-
 
1318
    SEXP s;
-
 
1319
    int n;
-
 
1320
    if (DispatchGroup("Math", call, op, args, env, &s))
-
 
1321
	return s;
-
 
1322
 
-
 
1323
    switch (n = length(args)) {
-
 
1324
    case 1:
-
 
1325
	check1arg(args, call, "x");
-
 
1326
	if (isComplex(CAR(args)))
-
 
1327
	    return complex_math1(call, op, args, env);
-
 
1328
	else
-
 
1329
	    return math1(CAR(args), atan, call);
-
 
1330
    /* prior to 2.3.0, 2 args were allowed,
-
 
1331
       but this was never documented */
-
 
1332
    default:
-
 
1333
	errorcall(call,_("%d arguments passed to 'atan' which requires 1"), n);
-
 
1334
    }
-
 
1335
    return s;			/* never used; to keep -Wall happy */
-
 
1336
}
-
 
1337
 
-
 
1338
 
1315
 
1339
/* The S4 Math2 group, round and signif */
1316
/* The S4 Math2 group, round and signif */
1340
/* This is a primitive SPECIALSXP with internal argument matching */
1317
/* This is a primitive SPECIALSXP with internal argument matching */
1341
SEXP attribute_hidden do_Math2(SEXP call, SEXP op, SEXP args, SEXP env)
1318
SEXP attribute_hidden do_Math2(SEXP call, SEXP op, SEXP args, SEXP env)
1342
{
1319
{
Line 1385... Line 1362...
1385
    }
1362
    }
1386
    UNPROTECT(nprotect);
1363
    UNPROTECT(nprotect);
1387
    return res;
1364
    return res;
1388
}
1365
}
1389
 
1366
 
-
 
1367
/* log{2,10} are builtins */
1390
SEXP attribute_hidden do_log1arg(SEXP call, SEXP op, SEXP args, SEXP env)
1368
SEXP attribute_hidden do_log1arg(SEXP call, SEXP op, SEXP args, SEXP env)
1391
{
1369
{
1392
    SEXP res, Call, tmp = R_NilValue /* -Wall */;
1370
    SEXP res, call2, args2, tmp = R_NilValue /* -Wall */;
1393
 
1371
 
1394
    checkArity(op, args);
1372
    checkArity(op, args);
1395
    check1arg(args, call, "x");
1373
    check1arg(args, call, "x");
1396
 
1374
 
1397
    if (DispatchGroup("Math", call, op, args, env, &res)) return res;
1375
    if (DispatchGroup("Math", call, op, args, env, &res)) return res;
1398
 
1376
 
1399
    if(PRIMVAL(op) == 10) tmp = ScalarReal(10.0);
1377
    if(PRIMVAL(op) == 10) tmp = ScalarReal(10.0);
1400
    if(PRIMVAL(op) == 2)  tmp = ScalarReal(2.0);
1378
    if(PRIMVAL(op) == 2)  tmp = ScalarReal(2.0);
1401
 
1379
 
1402
    PROTECT(Call = lang3(install("log"), CAR(args), tmp));
1380
    PROTECT(call2 = lang3(install("log"), CAR(args), tmp));
-
 
1381
    PROTECT(args2 = lang2(CAR(args), tmp));
-
 
1382
    if (! DispatchGroup("Math", call2, op, args2, env, &res)) {
-
 
1383
	if (isComplex(CAR(args)))
1403
    res = eval(Call, env);
1384
	    res = complex_math2(call2, op, args2, env);
-
 
1385
	else
-
 
1386
	    res = math2(CAR(args), tmp, logbase, call);
-
 
1387
    }
1404
    UNPROTECT(1);
1388
    UNPROTECT(2);
1405
    return res;
1389
    return res;
1406
 
-
 
1407
}
1390
}
1408
 
1391
 
-
 
1392
 
1409
/* This is a primitive SPECIALSXP with internal argument matching */
1393
/* This is a primitive SPECIALSXP with internal argument matching */
1410
SEXP attribute_hidden do_log(SEXP call, SEXP op, SEXP args, SEXP env)
1394
SEXP attribute_hidden do_log(SEXP call, SEXP op, SEXP args, SEXP env)
1411
{
1395
{
1412
    SEXP res, ap = args, call2;
1396
    SEXP res, ap = args, call2;
1413
    int n = length(args), nprotect = 2;
1397
    int n = length(args), nprotect = 2;