Skip to content

Commit 95455fb

Browse files
committed
[GR-14293] Additional native API functions.
PullRequest: fastr/1940
2 parents 822de35 + 9240686 commit 95455fb

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

com.oracle.truffle.r.native/fficall/src/common/arithmetic_fastr.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 1995, 1996, 1997 Robert Gentleman and Ross Ihaka
33
* Copyright (c) 1995-2014, The R Core Team
44
* Copyright (c) 2002-2008, The R Foundation
5-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates
5+
* Copyright (c) 2015, 2019, Oracle and/or its affiliates
66
*
77
* This program is free software; you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -206,3 +206,48 @@ double R_pow(double x, double y) /* = x ^ y */
206206
return R_NaN; // all other cases: (-Inf)^{+-Inf, non-int}; (neg)^{+-Inf}
207207
}
208208

209+
#define LDOUBLE double
210+
211+
double Rf_logspace_sum (const double* logx, int n)
212+
{
213+
if(n == 0) return R_NegInf; // = log( sum(<empty>) )
214+
if(n == 1) return logx[0];
215+
if(n == 2) return logspace_add(logx[0], logx[1]);
216+
// else (n >= 3) :
217+
int i;
218+
// Mx := max_i log(x_i)
219+
double Mx = logx[0];
220+
for(i = 1; i < n; i++) if(Mx < logx[i]) Mx = logx[i];
221+
LDOUBLE s = (LDOUBLE) 0.;
222+
for(i = 0; i < n; i++) s += EXP(logx[i] - Mx);
223+
return Mx + (double) LOG(s);
224+
}
225+
226+
attribute_hidden double Rf_d1mach(int i)
227+
{
228+
switch(i) {
229+
case 1: return DBL_MIN;
230+
case 2: return DBL_MAX;
231+
232+
case 3: /* = FLT_RADIX ^ - DBL_MANT_DIG
233+
for IEEE: = 2^-53 = 1.110223e-16 = .5*DBL_EPSILON */
234+
return 0.5*DBL_EPSILON;
235+
236+
case 4: /* = FLT_RADIX ^ (1- DBL_MANT_DIG) =
237+
for IEEE: = 2^-52 = DBL_EPSILON */
238+
return DBL_EPSILON;
239+
240+
case 5: return M_LOG10_2;
241+
242+
default: return 0.0;
243+
}
244+
}
245+
246+
#ifdef __cplusplus
247+
extern "C"
248+
#endif
249+
250+
double F77_NAME(d1mach)(int *i)
251+
{
252+
return Rf_d1mach(*i);
253+
}

com.oracle.truffle.r.native/fficall/src/common/util_fastr.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (c) 1995-2015, The R Core Team
33
* Copyright (c) 2003, The R Foundation
4-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates
4+
* Copyright (c) 2015, 2019, Oracle and/or its affiliates
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -396,3 +396,19 @@ double R_atof(const char *str)
396396
{
397397
return R_strtod5(str, NULL, '.', FALSE, FALSE);
398398
}
399+
400+
Rboolean Rf_StringBlank(SEXP x)
401+
{
402+
return x == R_NilValue || CHAR(x)[0] == (char) 0;
403+
}
404+
405+
Rboolean Rf_StringTrue(const char *name)
406+
{
407+
return strcmp(name, "T") == 0 || strcmp(name, "True") == 0 || strcmp(name, "TRUE") == 0 || strcmp(name, "true") == 0;
408+
}
409+
410+
Rboolean Rf_StringFalse(const char *name)
411+
{
412+
return strcmp(name, "F") == 0 || strcmp(name, "False") == 0 || strcmp(name, "FALSE") == 0 || strcmp(name, "false") == 0;
413+
}
414+

0 commit comments

Comments
 (0)