diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LogFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LogFunctions.java
index 59ba9f961eea560aaadd527e6d8eec5084f4b67b..ba7e5e0efbdfb10c73b567c97341057dd12ba9c1 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LogFunctions.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LogFunctions.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -239,7 +239,7 @@ public class LogFunctions {
         @TruffleBoundary
         private double logb(double x, double base, RBaseNode[] warningCtx) {
             double logx = Math.log(x);
-            if (Double.isNaN(logx)) {
+            if (!Double.isNaN(x) && Double.isNaN(logx)) {
                 warningCtx[0] = this;
             }
             if (base == Math.E) {
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
index c4da64760073c3adb183aecc9a3287836275c26d..30fad1fc9dd7709fa3ad58a14262bce08bfcce02 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
@@ -36110,6 +36110,30 @@ Error in lockEnvironment("foo", TRUE) : not an environment
 #{ log(1) } 
 [1] 0
 
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log.testLog#
+#{ log(1, NA) }
+[1] NA
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log.testLog#
+#{ log(1, NaN) }
+[1] NaN
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log.testLog#
+#{ log(NA) }
+[1] NA
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log.testLog#
+#{ log(NA, NA) }
+[1] NA
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log.testLog#
+#{ log(NaN) }
+[1] NaN
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log.testLog#
+#{ log(NaN, NaN) }
+[1] NaN
+
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_log.testLog#
 #{ log(c(0,1)) }
 [1] -Inf    0
@@ -36635,6 +36659,14 @@ NaNs produced
 #{ log10(100) } 
 [1] 2
 
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log10.testLog10#
+#{ log10(NA) }
+[1] NA
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log10.testLog10#
+#{ log10(NaN) }
+[1] NaN
+
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_log10.testLog10#
 #{ log10(c(0,1)) }
 [1] -Inf    0
@@ -36730,6 +36762,14 @@ sal
 spi
 wha
 
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log1p.testlog1p#
+#log1p(NA)
+[1] NA
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log1p.testlog1p#
+#log1p(NaN)
+[1] NaN
+
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_log1p.testlog1p1#
 #argv <- list(c(-0.160475096572577, -0.953101214495634, -0.329547420118877, -0.234819677566528, -0.108178529791777, -0.0994458210555148, -0.282992873965743, -0.731707656126625, -0.866467764292465, -0.76039953639421, -0.3580569675068, -0.52382260076554, -0.240530699925064, -0.236619747356161, -0.811827419307205, -0.154911720192001, -0.97472580847241, -0.464016625026599, -0.58493655376716, -0.230096919024049));log1p(argv[[1]]);
  [1] -0.1749191 -3.0597635 -0.3998023 -0.2676438 -0.1144893 -0.1047450
@@ -36750,10 +36790,6 @@ Error in log1p(c(1 + (0+1i), -1 - (0+1i))) :
 #{ as.integer(log2(6)*1000000) } 
 [1] 2584962
 
-##com.oracle.truffle.r.test.builtins.TestBuiltin_log2.testLog2#
-#{ log10(c(1+1i, -1-1i)) }
-[1] 0.150515+0.3410941i 0.150515-1.0232823i
-
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_log2.testLog2#
 #{ log2(0) }
 [1] -Inf
@@ -36770,10 +36806,22 @@ Error in log1p(c(1 + (0+1i), -1 - (0+1i))) :
 #{ log2(4) } 
 [1] 2
 
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log2.testLog2#
+#{ log2(NA) }
+[1] NA
+
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log2.testLog2#
+#{ log2(NaN) }
+[1] NaN
+
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_log2.testLog2#
 #{ log2(c(0,1)) }
 [1] -Inf    0
 
+##com.oracle.truffle.r.test.builtins.TestBuiltin_log2.testLog2#
+#{ log2(c(1+1i, -1-1i)) }
+[1] 0.5+1.13309i 0.5-3.39927i
+
 ##com.oracle.truffle.r.test.builtins.TestBuiltin_log2.testlog21#
 #argv <- list(48L);log2(argv[[1]]);
 [1] 5.584963
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log.java
index 0b69eddf0a7cd6a13139c1bd19c394d1b748c2ef..68ba4c31d0d189332976590262154aa3c7f07f37 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log.java
@@ -4,7 +4,7 @@
  * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * Copyright (c) 2012-2014, Purdue University
- * Copyright (c) 2013, 2017, Oracle and/or its affiliates
+ * Copyright (c) 2013, 2018, Oracle and/or its affiliates
  *
  * All rights reserved.
  */
@@ -33,6 +33,13 @@ public class TestBuiltin_log extends TestBase {
         assertEval("{ round( log(10,10), digits = 5 ) }");
         assertEval("{ log(c(2,3), NA) } ");
         assertEval("{ log(c(2,3), 0/0) } ");
+
+        assertEval("{ log(NaN) }");
+        assertEval("{ log(NA) }");
+        assertEval("{ log(1, NaN) }");
+        assertEval("{ log(1, NA) }");
+        assertEval("{ log(NaN, NaN) }");
+        assertEval("{ log(NA, NA) }");
     }
 
     @Test
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log10.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log10.java
index a7cf88d1a1eacf5fd0e1e9d05c139a66f037154b..9106aecd7647048038824e9c2101ea7cd529283f 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log10.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log10.java
@@ -4,7 +4,7 @@
  * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * Copyright (c) 2012-2014, Purdue University
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates
+ * Copyright (c) 2013, 2018, Oracle and/or its affiliates
  *
  * All rights reserved.
  */
@@ -66,5 +66,7 @@ public class TestBuiltin_log10 extends TestBase {
         assertEval("{ x <- c(a=1, b=10) ; round( c(log(x), log10(x), log2(x)), digits=5 ) }");
 
         assertEval("{ log10(c(1+1i, -1-1i)) }");
+        assertEval("{ log10(NaN) }");
+        assertEval("{ log10(NA) }");
     }
 }
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log1p.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log1p.java
index 4c5d09896c359232ae3a1194542d0bc691463215..4c7d79fd0895e535af9c7d2cfd9c4ddae408ac52 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log1p.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log1p.java
@@ -4,7 +4,7 @@
  * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * Copyright (c) 2014, Purdue University
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates
  *
  * All rights reserved.
  */
@@ -31,4 +31,10 @@ public class TestBuiltin_log1p extends TestBase {
     public void testlog1p3() {
         assertEval(Ignored.ReferenceError, "log1p(c(1+1i,-1-1i))");
     }
+
+    @Test
+    public void testlog1p() {
+        assertEval("log1p(NaN)");
+        assertEval("log1p(NA)");
+    }
 }
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log2.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log2.java
index 22f4772cc91705b5ad8ab872c0acb97982128184..7ed1236ae029c9f58c6c7f9d4762ed6c323c6292 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log2.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_log2.java
@@ -4,7 +4,7 @@
  * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * Copyright (c) 2012-2014, Purdue University
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates
+ * Copyright (c) 2013, 2018, Oracle and/or its affiliates
  *
  * All rights reserved.
  */
@@ -47,6 +47,9 @@ public class TestBuiltin_log2 extends TestBase {
         assertEval("{ log2(4) } ");
         assertEval("{ as.integer(log2(6)*1000000) } ");
 
-        assertEval("{ log10(c(1+1i, -1-1i)) }");
+        assertEval("{ log2(c(1+1i, -1-1i)) }");
+
+        assertEval("{ log2(NaN) }");
+        assertEval("{ log2(NA) }");
     }
 }